![]() |
CI4 libaries function call in VIEW - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: CI4 libaries function call in VIEW (/showthread.php?tid=77846) Pages:
1
2
|
CI4 libaries function call in VIEW - shashi - 10-26-2020 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 RE: CI4 libaries function call in VIEW - includebeer - 10-26-2020 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. RE: CI4 libaries function call in VIEW - shashi - 10-26-2020 (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 RE: CI4 libaries function call in VIEW - includebeer - 10-27-2020 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']) ?> RE: CI4 libaries function call in VIEW - shashi - 10-27-2020 (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 RE: CI4 libaries function call in VIEW - includebeer - 10-27-2020 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') ?> RE: CI4 libaries function call in VIEW - shashi - 10-27-2020 (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 ??? RE: CI4 libaries function call in VIEW - includebeer - 10-28-2020 (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 RE: CI4 libaries function call in VIEW - InsiteFX - 10-29-2020 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. RE: CI4 libaries function call in VIEW - includebeer - 10-29-2020 (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(); |