cakephp 2 with customize link code example

Example 1: cakephp 2 with customize link

Router::url('/', true) . 'img/example.png' (cakephp 2)

Example 2: cakephp 2 with customize link

1. Add .htaccess
<IfModule mod_rewrite.c>
	RewriteEngine on
	RewriteRule ^$ webroot/ [L]
	RewriteRule (.*) webroot/$1 [L]
</IfModule>

2. Add Permission tmp, Vendor, Webroot
- Window Set permisson
- Linux Set chmod -R 777

Example 3: cakephp 2 with customize link

// In mysql you can order by specific field values, by using ORDER BY FIELD:
SELECT * FROM city 
WHERE id IN (10, 1, 2)
ORDER BY FIELD(id, 10, 1, 2) DESC;

// output:
// order: first those with id = 10, those with id = 1, those with id = 2
// Do in cake
	'order' => array(
		'FIELD(City.id, 10, 1, 2)',
	),

// or
    'order' => array(
		'FIELD(City.id, 10, 1, 2) DESC',
	),

Example 4: cakephp 2 with customize link

//chnage the layout in Cakephp 4 with the layout file called ajax.php
$this->viewBuilder()->setLayout('ajax');

Example 5: cakephp 2 with customize link

echo $this->Html->link(__('<i class="fas fa-icons"></i>'), array(
  'plugin' => 'building', 
  'controller' => 'service_icons', 
  'action' => 'index', 
  '?building_post_id=' . $buildingPost['BuildingPost']['id']), array('class' => 'btn btn-info btn-xs', 'escape' => false, 'data-toggle'=>'tooltip', 'title' => __d('building', 'add_service_icon')));


// output
// http://localhost/paragonasia-portal/admin/building/service_icons/index/?building_post_id=16

Example 6: cakephp 2 with customize link

// output, if you wanna get output same below array, you need to use name="Member[verify_code]" 
// name="Member[email]"  in form

Array(
    [Member] => Array   (
      [verify_code] => 123466
      [email] => [email protected]
      [lang] => zho
      [password] => 123
      [confirm_password] => 123
) )
  
  // cake php form
  <?=$this->Form->create('Member', array('role' => 'form')); ?>
  <fieldset>
  <?=$this->Form->input('lang', array('type' => 'hidden', 'value' => $lang, 'required'));?>

  <div class="form-group">
  <input type="hidden" name="Member[verify_code]" value="<?= isset($verify_code) && !empty($verify_code) ? $verify_code : ''; ?>" />
  </div>

  <div class="form-group">
  <input type="hidden" name="Member[email]" value="<?= isset($email) && !empty($email) ? $email : ''; ?>" />
  </div>

  <div class="form-group">
  <?=$this->Form->input('password', array('class' => 'form-control', 'placeholder' => __d('frontend', 'new_password'), 'label' => '', 'required')); ?>
  </div>
  </fieldset>
  <?=$this->Form->end(); ?>

Example 7: cakephp 2 with customize link

Prefix routing is just very difficult to understand

Example 8: cakephp 2 with customize link

// ------------------------------------
// ------------ one OR --------------
// ------------------------------------
$conditions = array(
    'OR' => array(
        array( 'MemberRole.school_id' 	=> array()),
        array( 'MemberRole.role_id' 	=> $role),
    );
);

// ------------------------------------
// ------------ multiple OR --------------
// ------------------------------------
 'OR' => array(
   array(
     'MemberRole.school_id' 	=> array(),
     'MemberRole.role_id' 	=> $role,
   ),
   array(
     'MemberRole.school_id' 	=> array(),
     'MemberRole.role_id' 	=>  Environment::read('role.register'),
   ),
   array(
     'MemberRole.school_id' 	=> $school_id,
     'MemberRole.role_id' 	=> Environment::read('role.register'),
   ),
   array(
     'MemberRole.school_id' 	=> $school_id,
     'MemberRole.role_id' 	=> $role
   )
 )

Tags:

Misc Example