CodeIgniter Forums
How to use method function modal data to view codeigniter 4.5.3 - 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: How to use method function modal data to view codeigniter 4.5.3 (/showthread.php?tid=91548)



How to use method function modal data to view codeigniter 4.5.3 - startup - 08-29-2024

i have two table cate and subcate
Modal.php below
PHP Code:
public function getCate(){}

public function 
subCate(){} 

Controller
PHP Code:
public function getCate(){

$data['getCate'] = $mCate->cate();



<strong>view</strong>
PHP Code:
how to get function subCate in view below:

foreach(
$getCate as $k =>$v){
echo 
$v;

//i want use method subcate here below
subcate $this->subcate($v->id)


can you show me how to use function method data in view above
thank


RE: How to use method function modal data to view codeigniter 4.5.3 - captain-sensible - 08-29-2024

lets clarify the question ... are you saying you dont quite get how to get data from a model class , which has been instantiated in a controller and that data is passed in the controller along the lines of .
Code:
Model class is say called BlogModel.php

in controller  there is a property called $handle;

$this->handle  = new BlogModel();
$result = this->handle->getArticle($slug);
//getArticle  is a method in BlogModel.php
// a variable $slug  is passed as a paramer into the model method
$data=[ 'title'=> 'something',
'results'=>$result];

echo view ('someview',$data);
in the view you can use
<?php foreach ($results as $stuff)
{
echo "<h11>".  $stuff ['tableFieldName'] ."   then next field ".$stuff['tableFieldName2']. "</h11>";


}
?>
if thats not what your after please elaborate


RE: How to use method function modal data to view codeigniter 4.5.3 - startup - 08-29-2024

(08-29-2024, 12:57 PM)captain-sensible Wrote: lets clarify the question ... are you saying you dont quite  get how to get data from a model  class  , which has been instantiated  in a controller and that data is passed  in the controller along the lines of .
Code:
Model class is say called BlogModel.php

in controller  there is a property called $handle;

$this->handle  = new BlogModel();
$result = this->handle->getArticle($slug);
//getArticle  is a method in BlogModel.php
// a variable $slug  is passed as a paramer into the model method
$data=[ 'title'=> 'something',
'results'=>$result];

echo view ('someview',$data);
in the view you can use
<?php foreach ($results as $stuff)
{
echo "<h11>".  $stuff ['tableFieldName'] ."  then next field ".$stuff['tableFieldName2']. "</h11>";


}
?>
if thats not what your after please elaborate
Thank you very much for your instructions but I want to ask if in codeigniter 4 can   get methods directly in the view as codeigniter 3 or not, 
I can write other function in controller to pass to view
by the way, thank you for your support


RE: How to use method function modal data to view codeigniter 4.5.3 - captain-sensible - 08-30-2024

The MVC pattern is to have the controller to use a model to get data then pass to view ; its the only way i have ever done it.


RE: How to use method function modal data to view codeigniter 4.5.3 - Renta Ardhana - 09-01-2024

In certain situations, we want the user to be able to modify the theme easily without directly interacting with the controllers or models. One possible solution is to use a View Model, which allows us to request data from the View components.


RE: How to use method function modal data to view codeigniter 4.5.3 - InsiteFX - 09-01-2024

CodeIgniter 4 User Guide - Building Responses - View Decorators

CodeIgniter 4 User Guide - Building Responses - View Cells