CI4 libaries function call in VIEW |
Hello Everyone,
I am using CI 4.0.4 XAMPP CONTROL 3.2.4 I AM USING CI 4.0.4 FOR MY ONGOING LIVE PROJECT CURRENTLY I AM FACING SOME ISSUE I HAVE CREATED LIBRARIES Code: <?php in basecontroller.php Code: protected $libcon; in products.php controller Code: <?php namespace App\Controllers; How i can i access libraries Check_operation in above products view file view file of products.php i taught of using Code: <?= view_cell('\App\Libraries\Product::Check_operation', ['4' , '7']) ?> but it giving me ArgumentCountError 0 in ci3 we can use directly in view like Code: <?php $this->libcon->Check_operation(4,7) ;?> but ci4 - cant please let me know
PHP Code: <?= view_cell('\App\Libraries\Product::recentPosts', ['4' , '7']) ?> You have no "recentPosts" function in you libraries. Adjust this line to call the right function. Also, unless it's to render a block of html to display in your view, you shouldn't call a library directly from your view.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/ (10-26-2020, 02:28 PM)includebeer Wrote: sorry sir , my bad by mistakenly putted that : have updated properly PHP Code: <?= view_cell('\App\Libraries\Product::Check_operation', ['4' , '7']) ?> still not getting don't want to render -- just need to call above method , then how to do . as its getting difficult for me, to understand thanks
In this example, they pass an array because the function expect an array as the only parameter.
For a list of parameters, I think you need to use the second example and specify the name of the parameters in a string. Try this: PHP Code: <?= view_cell('\App\Libraries\Product::Check_operation', 'final=4, operation=7']) ?>
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/ (10-27-2020, 04:25 AM)includebeer Wrote: In this example, they pass an array because the function expect an array as the only parameter. getting below message ArgumentCountError Too few arguments to function App\Libraries\Product::__construct(), 0 passed in H:\xampp749\htdocs\aks\system\View\Cell.php on line 123 and exactly 2 expected
I have an error in my example, remove the ] at the end:
PHP Code: <?= view_cell('\App\Libraries\Product::Check_operation', 'final=4, operation=7') ?>
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/ (10-27-2020, 02:47 PM)includebeer Wrote: I have an error in my example, remove the ] at the end: Sorry sir, my bad again but still getting below message ArgumentCountError Too few arguments to function App\Libraries\Product::__construct(), 0 passed in H:\xampp749\htdocs\aks\system\View\Cell.php on line 123 and exactly 2 expected after reading Quote:The only restriction is that the class can not have any constructor parameters. This is intended to be used within views, and is a great aid to modularizing your code. is that what error ???
(10-27-2020, 11:01 PM)shashi Wrote:Quote:The only restriction is that the class can not have any constructor parameters. This is intended to be used within views, and is a great aid to modularizing your code. Yes you found it! I didn’t see it at first, but the error message is pretty clear. The system instantiate your class with no parameter (because it wouldn’t know what to pass anyway), but your constructor expect 2 parameters: Quote:Too few arguments to function App\Libraries\Product::__construct(), 0 passed in H:\xampp749\htdocs\aks\system\View\Cell.php on line 123 and exactly 2 expected
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
He has his constructor setup to receive two values but he is passing in an array from the view.
he needs to change his constructor to an array or pass in another value in his view. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(10-29-2020, 03:27 AM)InsiteFX Wrote: He has his constructor setup to receive two values but he is passing in an array from the view. No he cannot change his constructor to an array, he needs to change his constructor to have no parameters. This is the code that is crashing in system/View/Cell.php at line 123 PHP Code: $instance = new $class();
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/ |
Welcome Guest, Not a member yet? Register Sign In |