Welcome Guest, Not a member yet? Register   Sign In
check view exist in codeigniter 4 not work
#1

hi .

check view exist in codeigniter 4 not work and return No

PHP Code:
    $template_overide=FCPATH.'app/views/templates/m_template/new_file.php';
    if(file_exists($template_overide) ){
              echo " | ok";
     }else{
              echo " | no";
    
Reply
#2

FCPATH is public/ folder.
And view folder is app/Views/.
Reply
#3

this return;
/home3/pakhshee/public_html/app/views/templates/skytheme/product_pdf_list_creator_pdf_template.php
Reply
#4

(This post was last modified: 01-16-2022, 06:08 AM by captain-sensible. Edit Reason: added stuff i forgot to post )

it it not going to involve a url in a web browser ; since thats what surfurews use ?

this is the code I use as part of one of my controllers (just to give food for thought for those that might find it of some use :

Code:
public function showme($page = 'home')
                        {
                            $this->cachePage(DAY);
                            
                            
                            $this->logic1=    file_exists(APPPATH.'/Views/'.$page.'.php');
                                
                                            if(( $this->logic1 == NUll)OR ($this->logic1 == False))
                                            
                                            {
                                            
                                            return redirect('noPage');
                                            
                                                
                                           }                                                        
                                            elseif(($this->logic1==1)OR($this->logic1==true))
                                            {
                                                
                                                $data = [
                                                        'title'  =>ucfirst($page)     ,
                                                        'date'=>$this->myDate
                                                ];
                                                
                                                                            
                                        
                                        
                                            echo view($page,$data);
                                            
                                            
                                        
                                    }

works for me



forgot to add i have this as a last route

Code:
$routes->get('(:any)', 'Pages::showme/$1');


in this line public function showme($page = 'home')
$page will be $1 from the url , so '.$page.'.php' becomes the url segment passed and I add .php to it , so that it can be searched for as a file.
CMS CI4     I use Arch Linux by the way 

Reply




Theme © iAndrew 2016 - Forum software by © MyBB