Passing Arguments problems |
[eluser]Richard Testani[/eluser]
I'm getting a range of errors trying to pass arguments to models and libraries. Code: //controller/index.php The above return 4 errors: Code: A PHP Error was encountered What is happening? I am my argument as an array. I've also written it out as: Code: $data = array('yes'); Any ideas what I am doing wrong or what is actually happening? Thanks Rich
[eluser]jedd[/eluser]
[quote author="Richard Testani" date="1249435817"] Code: //controller/index.php It is meaningless to pass data to a model class per se - you send data to a method within a model. The second parameter of a model load denotes an alternative name for the model (see the [url="http://ellislab.com/codeigniter/user-guide/general/models.html"]CI User Guide section on Models[/url] for more information) which explains the array to string conversion error.
[eluser]ecigraeme[/eluser]
You need to define a function in your model, call that function and pass a parameter to it. Code: //controller/index.php
[eluser]Johan André[/eluser]
The second argument of the load->model()-function is for creating a new name for the model: Code: $this->load->model('categories_model', 'cats'); You can't (afaik) pass arguments to a model constructor...
[eluser]jcavard[/eluser]
[quote author="Richard Testani" date="1249435817"]I'm getting a range of errors trying to pass arguments to models and libraries. Code: A PHP Error was encountered Code: A PHP Error was encountered Code: A PHP Error was encountered Code: A PHP Error was encountered The second argument passed when you load a model is the internal name of that model, example taken from the user guide you can do this way Code: $this->load->model('Model_name'); Code: $this->load->model('Model_name', 'MyFunkyModelNameCool'); You have a few things wrong in your code. Try this first Code: //controller/index.php
[eluser]Adam Griffiths[/eluser]
Index is also a reserved name in CodeIgniter for controllers. So you'll have to rename your controller, that's probably causing you some problems.
[eluser]Richard Testani[/eluser]
Wow - great help on this one. I had not realized, the special case of the model. I've renamed my Controller from Index which I found out in another case that it's a reserved name. Thanks everyone. Rich |
Welcome Guest, Not a member yet? Register Sign In |