codeigniter template engine like in Wordpress Or Joomla - codeigniter

Is there a Codeigniter Library or extension which would make possible dynamic templating like in Wordpress or Joomla. What I mean I would like to point my controller to a view which is specified by admin from back.
than I was starting to create by myself but till this point without any success
controller
--main_conroler
here some trying what did not succeed
class MainController extends CI_Controller {
/* Initiate Site
*/
private $method;
private $data;
function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->helper('language');
$this->method = $this->router->fetch_method();
if ($this->method == "index") {
$this->data['view'] = 'templates/appStrapp';
} elseif ($this->method != 'site' && method_exists(__CLASS__, $this->method)) {
$this->data['view'] = $this->method;
}
if (empty($this->data['view'])) {
show_404();
}
}
View
view
--templates
---default
----index.php
than here I would like to route my template parts
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
if (file_exists(dirname(__FILE__) . '/tmpl/' . $view . '.php')) {
include ( dirname(__FILE__) . '/tmpl/header.php');
include ( dirname(__FILE__) . '/tmpl/navigation.php');
$this->load->view('site/tmpl/' . $view);
include ( dirname(__FILE__) . '/tmpl/footer.php');
} else {
var_dump('test');
show_404();
}
?>

I've used the following for templates in CI and it's a nice setup.
https://github.com/philsturgeon/codeigniter-template

Related

Laravel Class 'Iyzipay\Options' not found

<?php
namespace App\Http\Controllers\Web;
use Iyzipay\Options;
class IndexController extends Controller
{
.
.
.
public function iyzico(Request $request){
$name = $request->get('name');
$card_no = $request->get('card_no');
$expire_month = $request->get('expire_month');
$expire_year = $request->get('expire_year');
$cvc = $request->get('cvc');
$user = Auth::user();
//options
$options = new Options();
$options->setApiKey("***");
$options->setSecretKey("***");
$options->setBaseUrl("***");
}
.
.
.
}
I'm doing something like this on controller.But I get the error Class 'Iyzipay\Options' not found. I checked the file path and it is correct. No matter what I did I couldn't fix the error
If you want to use iyzipay package, you should add to your composer:
composer require iyzico/iyzipay-php
Edit For Manual Usage:
If you want to use manual you can create Library folder under app directory. And paste iyzipay folder here.
Then create a file such as Iyzipay.php in Library folder.
app
-Library
--iyzipay-php
--Iyzipay.php
And Iyzipay.php (i recommend, don't use transaction process in your controller
<?php
namespace App\Library;
require_once dirname ( __FILE__ ) . '/iyzipay-php/IyzipayBootstrap.php';
class Iyzipay
{
public static function boot ()
{
\IyzipayBootstrap::init ();
}
public static function pay ( $apiInfo, $cartInfo, $price, $shippingTaxPrice = 0 )
{
....
....
}
}
and use in your controller like this:
<?php
...
...
use App\Library\Iyzipay;
...
...
Iyzipay::boot ();
$payment = Iyzipay::pay ( $apiResources, $cartInfo, $price) );

I need to create a folder by using codeigniter without button click

I need to create a folder to store user information at login. One login button should perform 2 actions.
They are
Login
Create folder
I need this in CODEIGNITER, please someone help me, I've been stuck with this for 4 weeks.
This is my code
<?php
ob_start();
defined('BASEPATH') OR exit('No direct script access allowed');
class LoginTwo extends CI_Controller
{
function __construct() {
parent::__construct();
$this->load->model("login_model", "login");
}
public function login()
{
$username = $this->input->post("username");
$password = $this->input->post("password");
$isCorrect = $this->login->validate_user($username, $password);
if($isCorrect)
{
// Start your user session
$dirName = $username;
$dirPath = "folder/".$dirName."/";
if (!file_exists($dirPath)) {
mkdir("folder/" . $dirName, 0777, true);
}
redirect("your user page");
}
else
{
redirect("homepage");
}
}
}?>
Try to use below mentioned solutions.
$path = FCPATH.'/uploads/';
$new_directory = 'name';
mkdir($path.$name,0755,TRUE);
In this
First_Param: pathname :Name of directory
Second_Param: mode: Permissions
Third Param : recursive : Allows the creation of nested directories
Check out the following code. You need to fit your requirements within this code block (you can change it if you have to do something more).
You controller function :
public function login()
{
$username = $this->input->post("username");
$password = $this->input->post("password");
$isCorrect = $this->user_model->checkCredentials($username, $password);
if($isCorrect)
{
// Start your user session
$dirName = $username;
$dirPath = "folder/".$dirName."/";
if (!file_exists($dirPath)) {
mkdir("folder/" . $dirName, 0777, true);
}
redirect("your user page");
}
else
{
redirect("homepage");
}
}

dynamically page load using codeigniter

helow, I am a newbie in codeigniter. I want to load my pages into my view dynamically. That means, Using a function.
For example i have 4 page home, about, contact, info. In my my view folder I have created a base layout where i include header and footer which is same for all those pages. now i want when i click those page link it just load into content body without loading full page. Using CI normal procedure i can do it. which is
function home(){
$data['main_content'] = 'home';
$this->load->view('template/layout', $data);
}
function about(){
$data['main_content'] = 'about';
$this->load->view('template/layout', $data);
}
but i want to create a function which call this pages into a single function for example,
function pageload($page){
}
this function check that requested file either exits or not exist. if exist it load the page otherwise load "page not found" 404 error page. How can I make it...plz help.
My view file is:
<nav>
<ul class="sf-menu">
<li class="current"><?php echo anchor('home/index', 'Home');?></li>
<li><?php echo anchor('home/amenities', 'Room & Amenitis');?></li>
<li><?php echo anchor('home/reservations', 'Reservations');?></li>
<li><?php echo anchor('home/photos', 'Photographs');?></li>
<li><?php echo anchor('home/pakages', 'Pakages');?></li>
<li><?php echo anchor('home/explore', 'Explore');?></li>
<li><?php echo anchor('home/contact', 'Contact');?></li>
</ul>
</nav>
And Controller:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller{
function __construct(){
parent::__construct();
}
function pageload($page){
$data['main_content'] = $page;
$this->load->view('template/layout', $data);
}
}
?>
You can do something lilke this
function pageload($page){
$data['main_content'] = $page;
$this->load->view('template/layout', $data);
}
if u dont want to show controller_name/pageload in url then in application/config/routes.php
add an array
$route['(home|about_us|other_page|another_page)'] = 'controller_name/pageload/$1';
and to load your 404 page just go to the application/config/routes.php
find this line $route['404_override'] and set its value to snything u want like
$route['404_override'] = 'page_not_found';
then in your controller just add a controller named page_not_found.php and load ur desired 404 custom view from that controller.
Try this function i think this will help you
function build_view($flake) {
$this->data['content'] = $this->load->view($flake, $this->data, TRUE);
$this->load->view('header', $this->data);
}
after you add this you need to add to other function like in index function
function index(){
$this->$data['main_content'] = $page;
$this->build_view('template/layout.php')
}

Anchor Text - Can you hide it? (URL Helper)

Is there anyway to hide the anchor text of the generated by CI? I know I could hide this via CSS (i.e. negative text-indent), but that seems like a lot of unnecessary work. Why wouldn’t I just use a regular HTML coded anchor?
<?php echo anchor(base_url(),''); ?>
Perhaps they thought that people would likely be passing in a blank string more by mistake than by design, I don't know and can't answer that part of your question.
Using the CodeIgniter anchor method in the URL helper has the advantage of automatically adding in your website's base path if necessary.
If you want to keep using the CodeIgniter helper and have anchors with no anchor text, you have several options:
Option 1: Add a space in the second argument:
<?php echo anchor(base_url(),' '); ?>
Option 2: Extend the URL helper and remove the behaviour:
Go into application\helpers and make a new file, called MY_url_helper.php
You can then put code in there to either replace the anchor method or define an entirely new method.
Here are some code examples of what you could put in the file: (I've adapted the code from the url_helper in a CodeIgniter installation I had handy)
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('anchor_hide_text'))
{
function anchor_hide_text($uri = '', $title = '', $attributes = '')
{
$title = (string) $title;
if ( ! is_array($uri))
{
$site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri;
}
else
{
$site_url = site_url($uri);
}
if ($attributes != '')
{
$attributes = _parse_attributes($attributes);
}
return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
}
}
or
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function anchor($uri = '', $title = '', $attributes = '')
{
$title = (string) $title;
if ( ! is_array($uri))
{
$site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri;
}
else
{
$site_url = site_url($uri);
}
if ($attributes != '')
{
$attributes = _parse_attributes($attributes);
}
return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
}

precontroller hooks in codeigniter

I am using pre-controller hook codeigniter in my project
Description:
we are using subdomain concept and three templates(theme). eg: My site is xyz.com. this is having one first template.
some business signup with this xyz site. for eg. abc(business). We create abc.xyz.com. abc chooses 2 template. abc.xyz.com in browser need to show 2nd template. It is not showing 2nd template. it is showing only 1st template.
When we clicked any link on the site more than once , then the template 2 is set for abc.xyz.com link.
I am using codeigniter. loaded session, database in autoload files.
I used precontroller hook to check whether the url is xyz or any subdomain abc.xyz.com
In hook i am setting template if the url is subdomain one.
But template is not showing when abc.xyz.com is in browser. when i refresh the url for some clicks or clicked any of the header link some count , it showing the actual template of the business abc.
Please help me to fix this issue or provide me some solution .
<?php
class Subdomain_check extends CI_Controller{
public function __construct(){
parent::__construct();
$this->CI =& get_instance();
if (!isset($this->CI->session))
{
$this->CI->load->library('session');
}
}
function checking()
{
$subdomain_arr = explode('.', $_SERVER['HTTP_HOST']); //creates the various parts
if($subdomain_arr[0] == 'www')
{
$subdomain_name = $subdomain_arr[1]; //2ND Part
}
else
{
$subdomain_name = $subdomain_arr[0]; // FIRST Part
}
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
if( $subdomain_name != 'xyz' )
{
$where = array();
$where['subdomain_name'] = $subdomain_name;
$where['status'] = 1;
$this->db->from('subdomain_map');
$this->db->where($where);
$query = $this->db->get();
if($query->num_rows() < 1)
{
header('Location:http://xyz.com/index.php?/error');
}
else
{
$result = $query->row_array();
$this->CI->session->set_userdata('subdomain_id',$result['subdomain_id']);
$this->CI->session->set_userdata('subdomain_name',$result['subdomain_name']);
$org_id = gat_organisationid_using_subdomainid($result['subdomain_id']);
$this->CI->session->set_userdata('organisation_id', $org_id);
if($org_id)
{
$templ_id = get_templid_using_organisationid($org_id);
$org_logo = get_organisation_logo($org_id);
}
if($templ_id){
if($this->session->userdata('pinlogin'))
$this->CI->session->set_userdata('template_set', 4);
else
$this->CI->session->set_userdata('template_set', $templ_id);
}
if($org_logo)
$this->CI->session->set_userdata('org_logo', $org_logo);
}
}
else
{
$this->CI->session->unset_userdata('subdomain_id');
$this->CI->session->unset_userdata('subdomain_name');
if( $this->CI->session->userdata('user_id') && $this->CI->session->userdata('user_category')<=2 )
{
$this->CI->session->unset_userdata('organisation_id');
$this->CI->session->unset_userdata('org_logo');
}
}
}
}
Here is the basic check you need to support custom themes per subdomain
// Gets the current subdomain
$url = 'http://' . $_SERVER['HTTP_HOST'];
$parsedUrl = parse_url($url);
$host = explode('.', $parsedUrl['host']);
// store $host[0], which will contain subdomain or sitename if no subdomain exists
$subdomain = $host[0];
// check for subdomain
if ($subdomain !== 'localhost' OR $subdomain !== 'mysite')
{
// there is a subdomain, lets check that its valid
// simplified get_where using activerecord
$query = $this->db->get_where('subdomain_map', array('subdomain_name' => $subdomain, 'status' => 1));
// num_rows will return 1 if there was a valid subdomain selected
$valid = $query->num_rows() === 1 ? true : false;
if($valid)
{
// set theme, user_data, etc. for subdomain.
}
else
{
// get user out of here with redirect
header('Location: http://' . $_SERVER['HTTP_HOST'] . '/error');
exit();
}
}
Note that when using subdomains with codeigniter, you should set your config > base_url to the following:
$config['base_url'] = 'http://' . $_SERVER['HTTP_HOST'] . '/poasty/poasty-starterkit/';
this will ensure things like site_url() and other CI helpers still work.
Reading through your code may I suggest utilizing more of Codeigniters built-in functionality, for example your __construct function has a lot of un-necessary code:
Original code
public function __construct(){
parent::__construct();
/**
* CI already exists
* since this controller extends CI_controller, there is already and instance of CI available as $this.
$this->CI =& get_instance();
*/
/**
* duplicate check, CI checks if library is loaded
* and will ignore if loaded already
if (!isset($this->CI->session))
{
$this->CI->load->library('session');
}
*/
$this->CI->load->library('session');
}
Optimized for Codeigniter
public function __construct()
{
parent::__construct();
$this->CI->load->library('session');
}
I suggest reading up on the Codeigniter user_guide to better understand what codeigniter can do. #see http://codeigniter.com/user_guide/
I hope you find this helpful!

Resources