I just migrate a cakephp 2.5 app to a server with PHP 7.2 (before server has 5.6 to 7.1), so I should update core (2.10) and finally get to show the app correctley but I'm having issues when urls with parameters loads.
The error is when I try to load a view passing a parameter in URL the controller are not passing the data correctly to the template and get errors like Undefined variable: menu [APP/View/Layouts/default.ctp, line 97, for all variables.
include - APP/View/Layouts/default.ctp, line 97
View::_evaluate() - CORE/Cake/View/View.php, line 971
View::_render() - CORE/Cake/View/View.php, line 933
View::renderLayout() - CORE/Cake/View/View.php, line 546
View::render() - CORE/Cake/View/View.php, line 481
Controller::render() - CORE/Cake/Controller/Controller.php, line 968
Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 200
Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167
[main] - APP/webroot/index.php, line 109
I would aprreciate your opinions. Thanks.
For example I call view localhost.com/administrator/Banners/editarBigHomePage?id=351 and the template is full with Notices of undefinied variables, this just happens with URLS with parameters included.
Here is the view with variables:
public function editarBigHomePage()
{
$this->verificarUsuario();
if(!empty($this->request->params["url"]['id'])){
$id = $this->request->params["url"]['id'];
$categorias = $this->Categoria->find('all');
$this->set('categorias',$categorias);
$ciudades = $this->Ciudade->find('all');
$this->set('ciudades',$ciudades);
$publicidad = $this->Publicidade->findById($id);
$this->set('publicidad',$publicidad);
$this->set('menu','publicity');
$this->set('menu2','pase el menu por aqui');
}
if(!empty($this->request->data)){
$dataPublicidad= $this->request->data["Publicidade"];
$dataPublicidad["inhome"]=1;
if($this->Publicidade->save($dataPublicidad)){
$this->Session->setFlash('Publicity Edited','success');
return $this->redirect(array('controller'=>'Banners','action'=>'listarBigHomePage'),null,true);
}else{
$this->Session->setFlash('Error Publicity No Edited');
return $this->redirect(array('controller'=>'Banners','action'=>'listarBigHomePage'),null,true);
}
}
}
Related
The error is in below lines of the addressed file below (Line 186 & 187):
Website (Live): www.healthyminds.world
Tried restoring an earlier back-up(24 hours back), but that didn't work also.
Line 186 & 187 from source line:
$collections = get_option('google_typography_collections');
$google_fonts_all = $this->get_fonts();
$import_fonts = array();
if ($collections) {
foreach ($collections as $collection) {
$font_family = $collection['font_family'];
$font_index = array_search($font_family,
array_column($google_fonts_all,'family'));//Line 186
$font_variants = implode(',', $google_fonts_all[$font_index ['variants']); //Line 187
array_push(
$import_fonts,
array(
'font_family' => $collection['font_family'],
'font_variant' => $font_variants,
Error Messages (On All Pages Of Website, these are just few of the lines):
content/themes/elumine/includes/integrations/google-typography/google-typography.php on line 186
Warning: array_search() expects parameter 2 to be array, null given in /home/customer/www/healthyminds.world/public_html/wp-content/themes/elumine/includes/integrations/google-typography/google-typography.php on line 186
Warning: Illegal string offset 'variants' in /home/customer/www/healthyminds.world/public_html/wp-content/themes/elumine/includes/integrations/google-typography/google-typography.php on line 187
Warning: implode(): Invalid arguments passed in /home/customer/www/healthyminds.world/public_html/wp-content/themes/elumine/includes/integrations/google-typography/google-typography.php on line 187
You are getting the errors because on line 186 the $google_fonts_all either does not contain an array with 'family' key or it is not an array. In either case the expression, array_column($google_fonts_all, 'family'), returns empty.
You can extract the later expression into a variable:
$family = array_column((array)$google_fonts_all, 'family');
On the line 187, check for the isset( $google_fonts_all[$font_index]['variants'] ) either in a conditional statement or itenary.
Regards
Eliasu
Wisdom Labs has posted a patch to fix the problem.
I'm trying to add customers with a code but the PrestaShop is giving me a bug.
I'm using PHP and XML
$XMLRQString = '<?xml version="1.0" encoding="utf-8"?>'.
'<x:Winmax4GetEntitiesRQ xmlns:x="urn:Winmax4GetEntitiesRQ">'.
'</x:Winmax4GetEntitiesRQ >';
$Params=array(
'CompanyCode'=>'',
'UserLogin'=>'',
'UserPassword'=>'',
'Winmax4GetEntitiesRQXML'=> $XMLRQString
);
$return = $client->GetEntities($Params);
$XMLRSString = new SimpleXMLElement($return->GetEntitiesResult);
foreach ($XMLRSString->Entities->Entity as $entity)
{
$default_lang= Configuration::get('PS_LANG_DEFAULT');
$customer=new Customer();
$customer->email= $entity->Email;
$customer->lastname= $entity->EntityType;
$customer->firstname= [$default_lang => $entity->Name];
$customer->contribuinte= $entity->TaxPayerID;
$customer->passwd= $entity->TaxPayerID;
$customer->active = 1;
$customer->add();
}
ERROR: (1/1) ContextErrorException Warning: preg_match() expects
parameter 2 to be string, array given
in Validate.php line 172
at ValidateCore::isCustomerName(array(object(SimpleXMLElement))) in
ObjectModel.php line 1149
at ObjectModelCore->validateField('firstname',
array(object(SimpleXMLElement))) in ObjectModel.php line 981
at ObjectModelCore->validateFields() in ObjectModel.php line 284
at ObjectModelCore->getFields() in ObjectModel.php line 551
at ObjectModelCore->add(true, true) in Customer.php line 264
at CustomerCore->add() in create_clients.php line 66
When storing values from SimpleXML, if you just refer to the element itself by it's tag name - this will be an instance of SimpleXMLElement. As you want the actual content of the element, the simplest way to do this is to cast it to a string...
$customer->firstname= (string)$entity->Name;
There's something weird going on with server-side Datatables from this: https://github.com/n1crack/Datatables.
Don't understand what's going on, i do exactly the same thing as the examples but it simply doesn't work. According to the "where" example https://github.com/n1crack/Datatables/blob/master/public/examples/where/ajax.php, look how simple it should be:
$dt = new Datatables(new MySQL($config));
$dt->query("Select film_id as fid, title, description from film where film_id > 47 and film_id < 83");
echo $dt->generate();
My code:
$config = [ 'host' => 'localhost',
'port' => '3306',
'username' => 'root',
'password' => '',
'database' => 'sys_db_gincana' ];
$dt = new Datatables( new MySQL($config) );
$dt->query("
SELECT seen, id, name, cep, date_format(created,'%d/%m/%Y %h:%i:%s') as created
FROM user
");
echo $dt->generate();
Now look at what my js console prints from my ajax:
A PHP Error was encountered
Severity: 4096 Message: Argument 1 passed to
PHPSQLParser\builders\WhereBuilder::build() must be of the type array,
boolean given, called in C:\Program Files
(x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\gincana\vendor\greenlion\php-sql-parser\src\PHPSQLParser\builders\SelectStatementBuilder.php
on line 74 and defined Filename: builders/WhereBuilder.php
Line Number: 112
A PHP Error was encountered
Severity: Warning Message: Invalid argument supplied for
foreach() Filename: builders/WhereBuilder.php Line
Number: 114
A PHP Error was encountered
Severity: 4096 Message: Argument 1 passed to
PHPSQLParser\builders\WhereBuilder::build() must be of the type array,
boolean given, called in C:\Program Files
(x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\gincana\vendor\greenlion\php-sql-parser\src\PHPSQLParser\builders\SelectStatementBuilder.php
on line 74 and defined Filename: builders/WhereBuilder.php
Line Number: 112
A PHP Error was encountered
Severity: Warning Message: Invalid argument supplied for
foreach() Filename: builders/WhereBuilder.php Line
Number: 114
Fatal error: Call to a member function
fetch_assoc() on a non-object in C:\Program Files
(x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\gincana\vendor\ozdemir\datatables\src\DB\MySQL.php
on line 40
And if if i change the query to:
$dt = new Datatables( new MySQL($config) );
$dt->query("
SELECT seen, id, name, cep, date_format(created,'%d/%m/%Y %h:%i:%s') as created
FROM user
WHERE approved = 0 and canceled = 0
");
echo $dt->generate();
the error changes:
A PHP Error was encountered
Severity: Warning Message: array_merge(): Argument #2 is
not an array Filename: src/Datatables.php Line Number:
47
Fatal error: Call to a member function
fetch_assoc() on a non-object in C:\Program Files
(x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\gincana\vendor\ozdemir\datatables\src\DB\MySQL.php
on line 40
Well, the library is a bit new (january 2015), i wonder if someone that had success using it could help me.
Regards
The problem in the WhereBuilder comes from the PHPSQLParser, can you test the latest version from https://github.com/greenlion/PHP-SQL-Parser? It seems to be a simple SQL statement, so actually it should work. I have moved your issue to GitHub, please follow the changes there.
I'm trying to set variables for an HTML email template, but I can't seem to be able to access the variables. When I echo the variable name in the template, in the sent email it shows an error saying "undefined variable". In the error description, it even shows the variables that were set.
App::uses('CakeEmail', 'Network/Email');
$Email = new CakeEmail();
$Email->from(array('info#example.com' => 'Test'));
$Email->to('myemail#email.com');
$Email->subject('Test email variables');
$Email->template('layout_1');
$Email->emailFormat('html');
$Email->viewVars(array('input_1','test input 1'));
$Email->send();
The following error shows up in the email and I can actually see the "input 1" variable that I set.
NOTICE (8): UNDEFINED VARIABLE: INPUT_1 [APP/VIEW/EMAILS/HTML/LAYOUT_1.CTP, LINE 44]
CODE CONTEXT
<TR>
<TD CLASS="HEADER-BAR" VALIGN="TOP" STYLE="COLOR: #999; FONT-FAMILY: VERDANA; FONT-SIZE: 10PX; TEXT-TRANSFORM: UPPERCASE; PADDING: 0 20PX; HEIGHT: 15PX;" WIDTH="400"
HEIGHT="15">
<?PHP PRINT_R($INPUT_1); ?>
$VIEWFILE = '/APPLICATIONS/XAMPP/XAMPPFILES/HTDOCS/APP/VIEW/EMAILS/HTML/LAYOUT_1.CTP'
$DATAFORVIEW = ARRAY(
'CONTENT' => '',
(INT) 0 => 'INPUT_1',
(INT) 1 => 'TEST INPUT 1'
)
$CONTENT = ''
INCLUDE - APP/VIEW/EMAILS/HTML/LAYOUT_1.CTP, LINE 44
VIEW::_EVALUATE() - CORE/CAKE/VIEW/VIEW.PHP, LINE 945
VIEW::_RENDER() - CORE/CAKE/VIEW/VIEW.PHP, LINE 907
VIEW::RENDER() - CORE/CAKE/VIEW/VIEW.PHP, LINE 471
CAKEEMAIL::_RENDERTEMPLATES() - CORE/CAKE/NETWORK/EMAIL/CAKEEMAIL.PHP, LINE 1582
CAKEEMAIL::_RENDER() - CORE/CAKE/NETWORK/EMAIL/CAKEEMAIL.PHP, LINE 1448
CAKEEMAIL::SEND() - CORE/CAKE/NETWORK/EMAIL/
CAKEEMAIL.PHP, LINE 1073
TEMPLATESCONTROLLER::SEND_NEWSLETTER() - APP/CONTROLLER/TEMPLATESCONTROLLER.PHP, LINE 110
TEMPLATESCONTROLLER::EDIT() - APP/CONTROLLER/TEMPLATESCONTROLLER.PHP, LINE 194
REFLECTIONMETHOD::INVOKEARGS() - [INTERNAL], LINE ??
CONTROLLER::INVOKEACTION() - CORE/CAKE/CONTROLLER/CONTROLLER.PHP, LINE 486
DISPATCHER::_INVOKE() - CORE/CAKE/ROUTING/DISPATCHER.PHP, LINE 187
DISPATCHER::DISPATCH() - CORE/CAKE/ROUTING/DISPATCHER.PHP, LINE 162
[MAIN] - APP/WEBROOT/INDEX.PHP, LINE 111
I also tried to print that $dataforview variable that shows, but I get the same error.
I haven't used cake in ages, but quickly looking at their docs they are expecting a key => value array passed to viewVars() method.
I assume you meant to do:
$Email->viewVars(array('input_1' => 'test input 1'));
Secondly, it looks like are you are defining the value as "input_1", but trying to access it as "INPUT_1". In PHP, variables are case sensitive.
In my CakePHP 2.2 application I get a "notice" inside my debug.log file. I get this warning nearly every day but I couldn't solve the problem. So I need to write some additional data inside debug.log. But I want to write that data when this "notice" occurs.
For example I get this notice:
2012-09-26 19:53:01 Notice: Notice (8):
Trying to get property of non-object in
[/var/www/vhosts/example.com/app/View/Tools/index.ctp, line 42]
Trace:
include - APP/View/Tools/index.ctp, line 42
View::_evaluate() - CORE/Cake/View/View.php, line 920
View::_render() - CORE/Cake/View/View.php, line 883
View::render() - CORE/Cake/View/View.php, line 475
Controller::render() - CORE/Cake/Controller/Controller.php, line 957
Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 193
Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 161
[main] - APP/webroot/index.php, line 96
I want to add all session variables into debug.log file when this notice occurs.
How can I do this?
Can I change lib/Cake/Log/Cakelog.php
What should I write and where?
Edit: I paste the related code snippet:
39 <?php if ($auth) { ?>
40 <form class="well" >
41
42 <?php if (isset($user->profile_url)) {
43 echo '<img src="'.$user->profile_url.'" width="48" height="48"/>';
44 } ?>
45
46 <strong><?php echo $user->screen_name; if (isset($user->name)) { echo " (" . $user->name . ")"; } ?></strong><br/>
47 <small><?php if (isset($user->description)) { echo $user->description; } ?> </small><br/>
48 <small><?php if (isset($user->url)) { echo $user->url; } ?> </small><br/>
49 <br/>