I am trying to use form_helper.php a helper class of codeigniter 2.2.0
and following is the error it's giving out when I try to do this :
controller file
$this->load->helper('form');
view file
<?php
$attributes = array('class' => 'form-horizontal', 'id' => 'admin-form');
echo form_open($this, $attributes);
?>
Error:
A PHP Error was encountered
Severity: Warning Message: strpos() expects parameter 1 to
be string, object given Filename: helpers/form_helper.php
Line Number: 53
A PHP Error was encountered
Severity: 4096 Message: Object of class CI_Loader could not
be converted to string Filename: helpers/form_helper.php
Line Number: 61
Although it does print the tag.
What I could be doing wrong here ?
Your code:
echo form_open($this, $attributes);
is in-correct. Correct it to:
echo form_open($YOUR_FORM_ACTION, $attributes);
Reference
Problem is occuring because, you are passing $this, an object instead of form action (string).
You can't use $this as the first argument as it is an internal CI object. Try:
echo form_open('controller/method', $attributes);
Related
I am trying to pass a value from my database to an input, but I throw the following error.I'm not sure if for this case you should use return $ this-> db-> get () -> row (); in the model. Any help is welcome.
A PHP Error was encountered
Severity: 4096
Message: Object of class stdClass could not be converted to string
Filename: usuarios/vConsulta_Horarios.php
Line Number: 590
Backtrace:
File: C:\xampp\htdocs\SAE\application\views\usuarios\vConsulta_Horarios.php
Line: 590
Function: _error_handler
File: C:\xampp\htdocs\SAE\application\controllers\cCalendar.php
Line: 26
Function: view
File: C:\xampp\htdocs\SAE\index.php
Line: 315
Function: require_once
Model (mCalendar)
public function lunes(){
$this->db->select('MIN(horario.hrs_ini)');
$this->db->from('horario');
$this->db->join('usuarios','horario.rut_usu = usuarios.rut_usu');
$this->db->where('usuarios.rut_usu','17811942-4');
$this->db->where('horario.lunes','ATTE. ESTUDIANTES');
return $this->db->get()->row();
Controller (cCalendar)
public function index(){
$this->load->view('layouts/header.php');
$this->load->view('layouts/menu.php');
$this->load->model('mCalendar');
$data['start_lunes'] = $this->mCalendar->lunes();
$this->load->view('usuarios/vConsulta_Horarios.php',$data);
$this->load->view('layouts/footer.php');
}
View
<div class="col-md-2">
<div class="form-group">
<label>fecha</label>
<input tupr="text" id="fecha_actual" name="fecha_actual" value="<?php echo $start_lunes;?>">
</div>
</div>
Even though you are only selecting one column, you still need to specify it when you output, because $start_lunes is the object that represents the entire row, and as the error tells you, it can't be converted to a string.
I think echo $start_lunes->hrs_ini should work.
Based on your updated function, I think it would be easier if you aliased the MIN expression in your select
$this->db->select('MIN(horario.hrs_ini) AS min_hrs');
Then refer to that in your view: echo $start_lunes->min_hrs
As return $this->db->get()->row(); returns object you are getting this error
You need to refer this link
So now, I will suggest you one thing to return data properly.
In your Controller change return $this->db->get()->row();
to
return $this->db->get()->result_array();
Now you are getting data in the format of Array and you can echo this in your View using
// In your view
foreach($start_lunes as $var){
$value = $var['MIN(horario.hrs_ini)'];
}
<input type="text" id="fecha_actual" name="fecha_actual" value="<?php echo $value?>"
My code in controller:
`
public function filetransport()
{
set_time_limit(0);
$message = new Zend_Mail_Message();
$message->addTo('matthew#zend.com')
->addFrom('ralph.schindler#zend.com')
->setSubject('Greetings and Salutations!')
->setBody("Sorry, I'm going to be late today!");
// Setup File transport
$transport = new Zend_Mail_Transport_File();
$transport->setOptions(array(
'path' => 'data/mail/',
'callback' => function (Zend_Mail_Transport_File $transport) {
return 'Message_' . microtime(true) . '_' . mt_rand() . '.txt';
},
));
$transport->send($message);
}
While creating instance of Zend_Mail_Message it is throwing error.The Error is
Catchable fatal error: Argument 1 passed to Zend_Mail_Message::__construct()
must be of the type array, none given,
called in C:\xampp\htdocs\Zend-Mailer\application\controllers\IndexController.php on line 102
and defined in C:\xampp\htdocs\Zend-Mailer\library\Zend\Mail\Message.php on line 57
If you have idea about this please let me know.....!
According to Zend documentation Zend_Mail_Message accepts one argument as the parameter. You are not passing any parameter. That is why you get this error.
__construct(array $params)
In addition to the parameters of Zend_Mail_Part::__construct() this
constructor supports:
file filename or file handle of a file with raw message content
flags array with flags for message, keys are ignored, use constants defined in Zend_Mail_Storage
Inherited_from \Zend_Mail_Part::__construct()
From Zend_Mail_Part docs,
Zend_Mail_Part supports different sources for content. The possible
params are:
handler a instance of Zend_Mail_Storage_Abstract for late fetch
id number of message for handler
raw raw content with header and body as string
headers headers as array (name => value) or string, if a content part is found it's used as toplines
noToplines ignore content found after headers in param 'headers'
content content as string
That means, as the error is saying, you are missing the params array in the constructor.
I'm working on a WordPress plugin and I want to create a new login error message like this:
I'm using this code for it:
add_filter( 'login_errors', $error );
$error = '<strong>ERROR:</strong> Code was invalid.';
However, I'm getting 3 errors.
Notice: Undefined variable: error in
\wp-content\plugins\directory\[cut].php
on line 119
Notice: Undefined offset: 0 in
[cut]plugin.php on line 925
Notice: Undefined offset: 0 in
[cut]plugin.php on line 943
I have tried to put $error above the filter, but that didn't work either.
What is going wrong??
Read documentation about add_filter function.
The second parameter is:
$function_to_add (callable) (Required) The callback to be run when the filter is applied.
It should be string with function name. In your case following code should work:
function return_custom_error() {
$error = '<strong>ERROR:</strong> Code was invalid.';
return $error;
}
add_filter( 'login_errors', 'return_custom_error' );
If you take a look at the codex for log_errors hook: https://codex.wordpress.org/Plugin_API/Filter_Reference/login_errors
the second parameter you should pass in is a function:
something like this:
add_filter( 'login_errors', function($error) { return $error = '<strong>ERROR:</strong> Code was invalid.';} );
SOLVED
I solved this issue with Jonathan Hussey help
I changed this line:
$mModel->getCollection()->load($mId)->getData();
for this:
$mModel->getCollection()->addFieldToFilter('met_id',$Id)->getSelect();
Problem
I created custom module which added tab to admin product page with additional text field.
When I try save this product I get this error:
a:5:{i:0;s:140:"Cannot send headers; headers already sent in /home/nano/domains/mydomain/public_html/gw/lib/Varien/Data/Collection/Db.php, line 693";i:1;s:1630:"#0 /home/nano/domains/mydomain/public_html/gw/lib/Zend/Controller/Response/Abstract.php(148): Zend_Controller_Response_Abstract->canSendHeaders(true)...
I saw that this error created in Observer.php:
$mId = $collection['m_id'];
$mModel->getCollection()->load($mId)->getData(); <-- this line give an error
$data['met_id'] = $mId;
$data['product_id'] = $product->getId();
$data['metf1'] = $this->_getRequest()->getPost('f1');
$mModel->setData($data);
$mModel->save();
Do you have any ideas how fix this ?
EDIT
content of admin template tab file:
<?php
$product = Mage::registry('current_product');
$mItem = Mage::getModel('mmodel/mmodel')->getCollection()->
addFilter('product_id',$product->getId())->getFirstItem();
echo '<div class="input-field">
<label for="f1">File</label>
<input type="text" class="input-text" name="f1" id="f1" value='.$mItem['f1'].' />
</div>';
Debug backtrace after line $mModel->getCollection()->load($mId)->getData(); from Observer.php
SELECT `main_table`.* FROM `mmodel` AS `main_table`
Debug Backtrace:
File Line Function
/home/nano/domains/mydomain/public_html/gw/app/code/local/GW/MModel/Model/Observer.php 42 printDebugBacktrace
/home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Model/App.php 1338 saveProductTabData
/home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Model/App.php 1317 _callObserverMethod
/home/nano/domains/mydomain/public_html/gw/app/Mage.php 468 dispatchEvent
/home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Model/Abstract.php 466 dispatchEvent
/home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Catalog/Model/Product.php 548 _afterSave
/home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Model/Abstract.php 319 _afterSave
/home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php 714 save
/home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Controller/Varien/Action.php 419 saveAction
/home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php 250 dispatch
/home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Controller/Varien/Front.php 176 match
/home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Model/App.php 354 dispatch
/home/nano/domains/mydomain/public_html/gw/app/Mage.php 704 run
/home/nano/domains/mydomain/public_html/gw/index.php 87 run
When working with collections you should only pass arguments to ->load() if you want the SQL for that collection to be logged or output. If you don't want the collection to return all items you can pull the select object from the collection with ->getSelect() and filter with standard Zend methods this way.
If you trace back your collection command you will see because you pass an argument it echo's out the collection SQL.
$mModel->getCollection()->load($mId)->getData();
Have a look at lib/Varien/Data/Collection/Db.php as per the error message and find the load() method. You will see that it accepts two aguments, $printQuery and $logQuery, you have passed an argument to $printQuery. A few lines down in the method you see:
$this->printLogQuery($printQuery, $logQuery);
Looking at the printLogQuery() method you will see that anything passed as the $printQuery argument which evaluates to true triggers the echo on line 693 as per the error message:
echo is_null($sql) ? $this->getSelect()->__toString() : $sql;
This is what is sending headers in your case. Remove the argument from ->load() or pass false and it should fix your problem.
Hello I have two questions:
(1) Is it best practice to create global custom functions in the bootstrap file? Is there a better place to store them?
(2) I am unable use the following line of code in my custom function located in my bootstrap.php file:
$url = $ajax->link ( 'Delete', array ('controller' => 'events', 'action' => 'delete', 22 ), array ('update' => 'event' ), 'Do you want to delete this event?' );
echo $url;
I receive the following error:
Notice (8): Undefined variable: ajax [APP\config\bootstrap.php, line 271]
Code
}
function testAjax () {
$url = $ajax->link ( 'Delete', array ('controller' => 'events', 'action' => 'delete', 22 ), array ('update' => 'event' ), 'Do you want to delete this event?' );
testAjax - APP\config\bootstrap.php, line 271
include - APP\views\event\queue.ctp, line 19
View::_render() - CORE\cake\libs\view\view.php, line 649
View::render() - CORE\cake\libs\view\view.php, line 372
Controller::render() - CORE\cake\libs\controller\controller.php, line 766
Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 211
Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 181
[main] - APP\webroot\index.php, line 91
However it works as intended if I place that same code in my view:
<a onclick=" event.returnValue = false; return false;" id="link1656170149" href="/shout/events/delete/22">Delete</a>
Please help :)
Thanks in advance!!
That depends: If it's a complete generic function that could be accessed from everywhere in your app, than yes. Otherwise I would place it in the parent-class from where you want to use it (app_model, app_controller)
$ajax is a helper class, that cannot be accessed from your bootstrap file. You would need to inculde the helper in the bootstrap, and that is the point from where it doesn't make sense to place the function there
Don't do it in bootstrap - no good place for that.
If You want to have this url on every page - put it in Your layout (http://book.cakephp.org/view/96/Layouts)