Welcome Guest, Not a member yet? Register   Sign In
How to use method function modal data to view codeigniter 4.5.3
#1

(This post was last modified: 08-29-2024, 12:54 AM by startup.)

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
Reply
#2

(This post was last modified: 08-29-2024, 01:02 PM by captain-sensible.)

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
CMS CI4 A CMS system, runs out of the box written on top of CI4
Arch Book  CodeIgniter4 on Apache(pages 92-114) 
Reply
#3

(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
Reply
#4

(This post was last modified: 08-30-2024, 01:09 AM by captain-sensible. Edit Reason: error )

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.
CMS CI4 A CMS system, runs out of the box written on top of CI4
Arch Book  CodeIgniter4 on Apache(pages 92-114) 
Reply
#5

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.
Reply
#6

CodeIgniter 4 User Guide - Building Responses - View Decorators

CodeIgniter 4 User Guide - Building Responses - View Cells
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB