For some reason my cakephp application is not showing any of the queries made to the database. It prints the table fine, but there are not records. What could cause this?
Check to make sure you are pulling the records correctly.
$models = $this->Model->find('all');
// or
$this->Model->recursive = 0;
$this->set('models', $this->paginate());
Then when you add them in the view, be sure you are looping through them correctly:
foreach ($models as $model) {
echo $model['Model']['field_name'];
}
UPDATE
To show the SQL statements, be sure you have the following set in core.php
Configure::write('debug', 2);
Also, in the Layout, besure you have this included someone between the <body> and </body> tags:
<?php echo $this->element('sql_dump'); ?>
I assume that you are getting an empty table with just the "Nr","Query","Error", etc. column headers?
You are getting the empty table because you have "Configure::write('debug',0);" set somewhere before you have "Configure::write('debug',2);" set. Find the first instance of it and delete it or change it to "2".
I know that you have long since fixed this problem but hopefully it helps somebody else in the future.
The CakePHP debug kit can help you. After you install it, you will notice a small (pie-chart) icon on the top right of your CakePHP pages. Clicking on that will allow you to see various useful information, and most importantly for this issue, all the SQL queries that occurred in the back-end upon the page loading.
I faced a similar problem in cakephp. I found that debug($variable) has limitation to the content size. Since you are fetching huge sized content from database, it is not able to print. Try doing print_r($variable) instead. To format it properly, you can do like this
echo "<pre>".print_r($variable)."</pre>";
Related
I built a homepage for my WordPress site from scratch, copying the style of the theme Reflex (which I actually bought). I'm doing this because this way the site is faster, and uses a lot less bandwidth.
Original site and my build
But, I'm having trouble getting the featured images, I wrote some quick code just to work it out:
<img src="'.$thumb_img.'-200x200.jpg">
I add "-200x200" at the end of the url which I got from the database. I understand this is not the best way to do this, so the question is: what's the best practice here?
Also: am I right in rewriting WordPress' frontend for performance? Is there a better approach or solution that you can think ok?
Thanks in advance!
Try this:
<?php the_post_thumbnail( array(200, 200) ); ?>
or, if you are not in the loop, try this:
<?php
$post_id = 54; //the post id that you want to display
echo get_the_post_thumbnail( $post_id, array(200, 200) );
?>
Also, please see: https://codex.wordpress.org/Function_Reference/the_post_thumbnail
and http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
I just installed Bugzilla locally and it seems that everything is fine. I can create new products and components. I can also file new bugs and they show up in the database.
But when I want to view them in the web interface, they won't show up.
Instead, at the top of the page this shows up:
Product: ARRAY(0x3735378 Component: ARRAY(0x4275650) Resolution: ARRAY(0x42755a8)
and then below the "Zarro Boogs found."
I couldn't find any information on that on the web, did anybody have similar issues? Thank you!
Please check the bugs table in techzilla database and verify if the bug details are getting updated.
The cgi file which corresponds to the listing of bugs is buglist.cgi.
Template file is:-global/message.html.tmpl
"Zarro Boogs found." is showing because, the values are not correctly entering in the query to display the buglist.
It is evident from the display,
Product: ARRAY(0x3735378 Component: ARRAY(0x4275650) Resolution: ARRAY(0x42755a8)
it is because of the looping problem.
check the display code in the template file or buglist file and correct the loop, then it will dsiplay properly
Jenifer,
Yes, It is because of the zero value in the query. We can check it, by printing the query and checking the value in DB.
Inserts a Named Query (a "Saved Search") into the database, or updates a Named Query that already exists..
We had similar problem. Bugs were not showing in search result list. The problem was in the name of the product when the name of the product was with diacritics (e.g. Czech, Slovak, etc...). When the name of the product is in US ASCII it is all Ok.
So I gather I can render a specific element of the $page['content'] array like so...
<?php print render(field_view_field('node', $node, 'field_image')); ?>
Where out of the box this will render the element as expected with standard defaults. Ok, so how can I make sure that hand plucked element no longer renders in the <?php print render($page['content']) ?> call later?
Why do I want something dumb like this? Because every page WILL have a header image with a few css tricks for overlays, design and such. But not every page will have attachments, links, and so on... you know, things that are additional fields in the page. So I can't manually print out each field since I don't know how many or what else there is. All I know for sure is the field_image I'm printing above is wrapped in a ton of markup for styling and must be done this way. Same for a few other fields.
Basically I'm looking for a way to unset the field immediately after use.
Does anyone know how to achieve this? I'd rather not make a view or a custom block that displays for specific pages. I eventually have to hand this over to a client who will not be able to wrap their heads around a single page being administered over many places in the CMS.
You can in fact control the display of individual fields for content types in Drupal without having to resort to the function you've used.
Since you know in advance which field(s) you want to suppress, you can turn off its display in the content type settings.
In Drupal 7, see:
Admin >> Structure >> Content types >> your content type >> Manage display
Under "Format" select < Hidden > for the field that you want to omit.
This will prevent the field contents from being displayed within the usual node contents, but field_view_field will naturally still work.
You can also fine-tune your field formats based on different view modes, e.g. choose to display the field within teasers but not in full content.
Looks like this will work:
<?php
print render(field_view_field('node', $node, 'field_image'));
MYTHEME_remove_item($page['content'], 'field_image');
?>
and in template.php file I made this function:
function MYTHEME_remove_item(&$content, $field)
{
foreach($content['system_main']['nodes'] AS $key => $val){
unset($content['system_main']['nodes'][$key][$field]);
}
}
This is ridiculous, in my opinion. I would think a system as robust as drupal would have a solution for something like this. If anyone knows the proper way to do this I will gladly mark them as correct. In the meantime, for others facing similar situations, this worked for me.
I dont understand why I am not able to update a field on the database based on the following code:
$this->User->id = 1;
$this->User->saveField('image','img/default_pic.png');
Basically, I want to change the current image in the Db with a new one.
The code above just clears the value that is currently in the image field, but does not add anything.
As an example, this is what happens:
id username image
=============================
1 admin mypic.jpg
2 john johnPic.jpg
After the code above is executed I get the following result
id username image
=============================
1 admin
2 john johnPic.jpg
I am confused at what is actually happening
SOLVED!
I decided to go back and check on my user.php model class and realized that I had attempted to use MeioUpload before and gave up, but I never removed the var actsAs entry.
As soon as I commented it out, I am now able to upload pictures.
For anyone else that might come across this issue, beforeSave might also caused these kind of problems, according to the following blog: http://blog.phplabs.net/2011/11/cakephp-savefield-not-working.html
Thanks,
What does the sql log say is happening?
My guess is you are actually doing something like
$this->User->saveField('image', $variable)
and $variable is either misspelled or is empty.
I'm making a website with two different databases. Let's say one is DB1, and the other is DB2. I've set up my database.php in the config folder, so they each have the correct host/password/username/database etc with db['DB1']['hostname'] and the other db['DB2']['hostname'] etc, so I'm pretty sure I've got that part right.
According to CodeIgniter docs, I'm supposed to do $this->load->database('DB1') to get that one to work within my model. First, I put it in my constructor for my model, and it didn't work. Then I tried putting that line as the first line of every function in the model, and that didn't work. I'm still getting this error:
Error Number: 1146
Table 'DB2.stores' doesn't exist
When I'm trying to use DB1, and have done $this->load->database('DB1') as the first line of the model's function. Does anyone know what I'm doing wrong? Thanks!
There are a couple of caveats I ran into when I last tried to do that.
In your model constructor, load DB1 and DB2 as
$this->DB1=$this->load->database('DB1',true) //<-- notice the true parameter
$this->DB2=$this->load->database('DB2',true) //<-- notice the true parameter
and then use $this->DB1->get()->where()->result_array() etc.etc.
Caveat 2
make sure persistent connections are off... they are on by default in CI
$db['DB2']['pconnect'] = FALSE;
and
$db['DB2']['pconnect'] = FALSE;
in your application/config/database.php file
hope that helps...