How to navigate controller folder using create URL - php

The controller:
controllers
|-SiteAction(folder)
|-1700(folder)
|-Participate.php
|-SiteController
How to render Participate.php class using CreateUrl?
<?=$this->createUrl('siteActions/1700/participate/'?>
is this code write?

Related

View file is not showing anything in a controller file in core folder

I have a controller file located in the core folder of my website.
I am trying to load a view file $this->load->view('nolocation');
however it's just loading a blank page, when i do the code above on any other controllers in the controller folder it shows properly.
Any ideas? Basically i want it to load a view when it cant determine the users location and not load the rest of the website.
thanks
You can check the user's location in constructor of every controller class.
Example
public function __construct(){
parent::__construct();
if(isset_location()){
redirect(base_url("nolocation")); //redirecting to the controller that specificaly designed to handle users with no location
}
}

How to add a folder in HMVC structure CodeIgniter?

I have file structure in CodeIgniter for HMVC everything is working fine
But I want file structure like
modules
admin
user
controller
view
model
profile
controller
view
model
frontend
login
, controller
view
model
Currently it's working fine with this file structure
modules
user
controller
view
model
profile
controller
view
model
So how can use as i mentioed above i just to add a folder before.
I want the URL like example.com/admin/user
Currently working example.com/user
You can set your route like this
$route['admin/([a-zA-Z_-]+)/(:any)/(:any)'] = '$1/$1_admin/$2/$3';
$route['admin/([a-zA-Z_-]+)/(:any)'] = '$1/$1_admin/$2';
$route['admin/([a-zA-Z_-]+)'] = '$1/$1_admin/index';
And change your class name controller
Like this
class User_admin extends CI_Controller
{
...
}
You can see my code on github
github.com/caktopik/haci
Or if you want to create admin panel please read this
https://philsturgeon.uk/codeigniter/2009/07/08/Create-an-Admin-panel-with-CodeIgniter/

Can't find the true url in a php project using Yii2

I'm new in php coding and I'm using Yii2 framework
I'm trying to make a simple project as follow:
I added a .php file named "PostController.php" in the backend/controllers and I wrote this codes in this file:
<?php
namespace backend\controllers;
use yii\web\Controller;
class PostController extends Controller
{
public function actionIndex()
{
return $this->render('index');
}
}
?>
and I created a file in beckend/views named "post" and in this folder I created a.php file named index.php
then I just wrote one line in index.php for test as bellow:
<h1>Hello World</h1>
Now I want to see this index file (Hello World) in my browser. Which url I should enter in my browser to see that? I tried the bellow url and it didn't worked!:
projectname.loc/index.php?r=post/index
if pretty url is true then you have to access the controller like
localhost/projectname/backend/web/index.php/controller/action
if pretty url is false then you have to access the controller like
localhost/projectname/backend/web/index.php?r=controller/action
if you project is in your local machine, if its on your server then you have to write server name instead of localhost
You should go to projectname.loc/post (or projectname.loc/post/index), to be in this action. before that you have to turn on the "prettyUrl" in your urlManager
If you use basic tamplate from yii2 your namespace must be app/backend/controllers and you should go to projectname.loc/index.php?r=backend/post/index
"backend" it will be a path to your controller, not a module

How to start a new website project in codeigniter?

I'm really beginner to codeigniter I'm working on CI since last 2 weeks. During this period I have created many views.php files, some controllers.php files and some models.php files
Now I want start a new website project.
What should I do. Should I delete all files of my controllers, views and models, etc., and download another codeigniter and start from the beginning?
You should check the documentation of codeigniter for help but just to give you a quick start ill explain how to create your first codeigniter project.
Installation
1 Download the codeigniter framework from http://ellislab.com/codeigniter
2 upload it in root directory of your website or local apache server directory.
Creating your codeigniter project.
In codeigniter your controller will handle the url requests and load appropriate model and views. So the first step is to create your controller.
1 Creating your controller: go to Applications->controllers and there you will find a built in controller called welcome.php.
This controller loads a view welcome_message.php which is inside Application->views.
You can use this controller or create your own.
To create your own controller create a new php file myfirstcontroller.php and extend a class with same name from CI_Controller.
Note that the name of the file and your class name should be the same. the index function is the default function that will be called when you make a request to the controller
class myfirstcontroller extends CI_Controller {
public function index(){
$this->load->view("myfirstview");
}
}
so when you request this controller through yoursite/index.php/myfirstcontroller
it will load a view called myfirstview.php which will reside inside applications->views.
Go ahead and create this file in applications ->views.
2 To pass data from controller to view you will send an array to the view
class myfirstcontroller extends CI_Controller {
public function index(){
$data['name']="My first application.";
$this->load->view("myfirstview",$data);
}
}
3 You can access this variable in view
echo $name
and it will output your variable
3 you use models you have to create a file inside applications->models and call it from controller and it will return the result in the form of array.
You can look at the documentation for further help.
Hope this helped you to get started with codeigniter.
The user guide is inside your download library.
You can also view it in http://ellislab.com/codeigniter/user-guide/
Good luck!!!
Here is Phil Sturgeon's article on how to do multiple site on one CI instance, in here he explains 2 ways of doing it and describes pros and cons.
http://philsturgeon.co.uk/blog/2009/07/Create-an-Admin-panel-with-CodeIgniter
But in his latest articles he has told what happened to modular separation.
http://philsturgeon.co.uk/blog/2010/03/modular-separation-codeigniter-2

Zend Framework - Display form from different view

I have a LoginController, Login Model and Login View that matches.
On the login.phtml file I can use <?php $this->form; ?> to output the form as specified in the Login model.
I would like to however place this same "view" into the index.phtml file that has a different class and model etc..
How would I do this?
You can use partial view helper when some html is shared between different views.
Edit:
I forgot to wrote that there is also an action helper called viewRenderer that can be used to render different view script than the default one. For example, you could load login.phtml in your indexAction as follows:
$this->view->form = $yourForm;
$this->_helper->viewRenderer->setNoController(true); // to specify that login.phtml is in different controller than your indexAction (in necessary)
$this->_helper->viewRenderer('login/login'); // assuming login.phtml is in login controller folder

Categories