Welcome, Guest
You have to register before you can post on our site.

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 9,899
» Latest member: merlion
» Forum threads: 66,912
» Forum posts: 419,193

Full Statistics

Latest Threads
Update and Flash-data mes...
Forum: General Help
10 hours ago
» Replies: 2   » Views: 63
Some functions in Control...
Forum: Best Practices
10 hours ago
» Replies: 4   » Views: 93
Codeigniter 3 + HMVC (sub...
Forum: Addins
11 hours ago
» Replies: 0   » Views: 60
Do you have a hobby?
Forum: Lounge
Today, 10:02 AM
» Replies: 23   » Views: 4,543
ctype_digit() won't work ...
Forum: Installation & Setup
Today, 05:28 AM
» Replies: 3   » Views: 104
$data array becomes varia...
Forum: Model-View-Controller
Today, 04:29 AM
» Replies: 6   » Views: 954
Multiple table joins
Forum: General Help
Yesterday, 11:37 PM
» Replies: 2   » Views: 119
database seeding
Forum: Addins
Yesterday, 06:30 PM
» Replies: 4   » Views: 2,780
Any one know where i can ...
Forum: Lounge
Yesterday, 12:34 PM
» Replies: 7   » Views: 504
Store Notification Messag...
Forum: Best Practices
Yesterday, 09:29 AM
» Replies: 1   » Views: 100

 
  Codeigniter 3 + HMVC (sub-direcotry in modules)
Posted by: csanesz - 11 hours ago - Forum: Addins - No Replies

I use HMVC wiredesignz third party to use modular structure for Codeigniter.

I there a way to create a subfolder in the modules directory ?

I want something :

Code:
modules
   module1
      controllers
          Module1.php
      ...
   admin
      module2
          controllers
              Module2.php
           ...    
      module3
          controllers
              Module3.php
           ...

Of course I've tried to call with :
Code:
base_url('admin/module2/index');

I've got a 404 error. Is this possible ?

Thanks


  Update and Flash-data messages not working
Posted by: kirasiris - Today, 08:36 AM - Forum: General Help - Replies (2)

It's been a long time since I logged in here.

I do not want to bother that much so I'm not going to be writing a lot instead I'm just going to tell my problem and ask for help.

Here is my problem I'm doing a new CodeIgniter application and I'm creating the admin panel. So far I've been able to create new "page_categories" into my database and I can fetch them with not problem but when I try to update a single item for example I want to change the name of "page category 2" to whatever I want

page category 1
page category 2

the name which updates is the page category 1 , does anybody know how to fix this?

Here is my controller:

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Pages_categories extends CI_Controller {

    public function 
index(){
        
$data['subjects'] = $this->Pages_categories_model->get_list();

        
// Load template
        
$this->template->load('admin''default''pages_categories/index'$data);
    }

    public function 
add(){
        
$this->form_validation->set_rules('name''Name''trim|required|min_length[3]');

        if(
$this->form_validation->run() == FALSE){
            
// Load template
            
$this->template->load('admin''default''pages_categories/add');
        } else {
            
// Create Post Array
            
$data = array(
                
'name'    => $this->input->post('name')
            );

            
// Insert Subject
            
$this->Pages_categories_model->add($data);

            
// Activity Array
            
$data = array(
                
'resource_id'   => $this->db->insert_id(),
                
'type'            => 'subject',
                
'action'        => 'added',
                
'user_id'        => 1,
                
'message'        => 'A new page category was added ('.$data["name"].')'
            
);

            
// Insert Activity
            
$this->Activity_model->add($data);

            
// Set Message
            
$this->session->set_flashdata('success''Page category has been added');

            
// Redirect
            
redirect('admin/pages_categories');
        }
    }

    public function 
edit($id){
        
$this->form_validation->set_rules('name''Name''trim|required|min_length[3]');

        if(
$this->form_validation->run() == FALSE){
            
// Get Current Subject
            
$data['item'] = $this->Pages_categories_model->get($id);

            
// Load template
            
$this->template->load('admin''default''pages_categories/edit'$data);
        } else {
            
$old_name $this->Pages_categories_model->get($id)->name;
            
$new_name $this->input->post('name');

            
// Create Post Array
            
$data = array(
                
'name'    => $this->input->post('name')
            );

            
// Insert Subject
            
$this->Pages_categories_model->update($id$data);

            
// Activity Array
            
$data = array(
                
'resource_id'   => $this->db->insert_id(),
                
'type'            => 'subject',
                
'action'        => 'updated',
                
'user_id'        => 1,
                
'message'        => 'A page category ('.$old_name.') was renamed to ('.$new_name.')'
            
);

            
// Insert Activity
            
$this->Activity_model->add($data);

            
// Set Message
            
$this->session->set_flashdata('success''Page category has been updated');

            
// Redirect
            
redirect('admin/pages_categories');
        }
    }

    public function 
delete($id){
        
$name $this->Pages_categories_model->get($id)->name;

        
// Delete Subject
        
$this->Pages_categories_model->delete($id);

        
// Activity Array
            
$data = array(
                
'resource_id'   => $this->db->insert_id(),
                
'type'            => 'subject',
                
'action'        => 'deleted',
                
'user_id'        => 1,
                
'message'        => 'A page category was deleted'
            
);

            
// Insert Activity
            
$this->Activity_model->add($data);

            
// Set Message
            
$this->session->set_flashdata('success''Page category has been deleted');

            
// Redirect
            
redirect('admin/pages_categories');
    }


Here is my model:
PHP Code:
<?php
class Pages_categories_model extends CI_MODEL{
    function 
__construct(){
        
parent::__construct();
        
$this->table 'pages_categories';
    }

    public function 
get_list(){
        
$query $this->db->get($this->table);
        return 
$query->result();
    }

    public function 
get($id){
        
$query $this->db->get($this->table);
        
$this->db->where('id'$id);
        return 
$query->row();
    }

    public function 
add($data){
        
$this->db->insert($this->table$data);
    }

    public function 
update($id$data){
        
$this->db->where('id'$id);
        
$this->db->update($this->table$data);
    }

    public function 
delete($id){
        
$this->db->where('id'$id);
        
$this->db->delete($this->table);
    }


and here is my view:
PHP Code:
<h2 class="page-header">Edit Page Category</h2>

<?
php echo form_open('admin/pages_categories/edit/'.$item->id); ?>
    <div class="form-group">
        <?php echo form_label('Page Category Name''name'); ?>
        <?php
            $data 
= array(
                
'name' => 'name',
                
'id'    => 'name',
                
'maxlength'    => '100',
                
'class'        => 'form-control',
                
'value'        => $item->name
            
);
        
?>
        <?php echo form_input($data); ?>
    </div>

    <?php echo form_submit('mysubmit''Update Page Category', array('class' => 'btn btn-primary')); ?>
<?php 
echo form_close(); ?>


  Some functions in Controller
Posted by: rolly - Today, 08:25 AM - Forum: Best Practices - Replies (4)

hi, I have any controllers with some functions


PHP Code:
class Foo extends CI_Controller
{
 
  private function _bar() {
 
     // something
 
  }

I need function _bar use in other controllers. Now I useing this function _bar repeat everytime in other controllers.
How not to write one and the same function all the time?


  Multiple table joins
Posted by: codeguy - Yesterday, 06:12 PM - Forum: General Help - Replies (2)

To make maintenance easier and possibly get better performance I have split a large table 'widgets' with many columns into 4 smaller tables; widgets, tags, links and notes. For each widget row there are a fixed number of tags but a widget row can have any number of links or notes - from none to many. 

The widget table has columns: widgetID, name, color and foreign key userID from a 'users' table.
The tags table has columns: tagID, tagName, and foreign key: widgetID.
The links table has columns: linkID, linkDesc, linkURL and foreign key widgetID.
The notes table has columns: notesID, dateEnt, dateLastEdit and foreign key widgetID.

The xID columns are all PRIMARY KEY AUTO_INCREMENT except when they're foreign keys.  I'm using mysqli driver.

This is my query to create array of objects that can populate all the variables in a grid view:

Code:
public function getWidgetGridData() {
   $userID=$this->session->userdata('userID');
    $objArr=$this->db
        ->select(
           'A.widgetID, A.name, A.color, 
            B.tagBank1, B.tagBank2, B.tagBank3, B.tagBank4,
            C.linkID, C.linkDesc, C.linkURL,
            D.dateEnt, D.dateLastEdit, D.content'
        )
        ->from('items A')
        ->join('tags B','A.widgetID= B.tagID', 'left')
        ->join('links C','A.widgetID= C.linkID', 'left')
        ->join('notes D','A.widgetID= D.noteID', 'left')
        ->where('A.userID',$userID)
        ->order_by('A.title','asc')
        ->get()->result(); 
   
     return $objArr // should return array of objects to controller (one for each select col)
It kind of works but never correctly yet. I tried various combos of link types and various sequence of statements. Sometimes it repeats some widget rows a number of times that matches the number of links for that widget. (Should be only one row per widget). Sometimes it doesn't list a widget row at all when there are no links present for that widget. Sometimes it just lists a single widget row - maybe associated with the fact there's only one note for one widget in the note table. When I comment out the links and notes joins, it works fine (i.e with just the tags join).
Any suggestions greatly appreciated.


  ctype_digit() won't work on a VPS server
Posted by: valkaycelestino - Yesterday, 02:34 PM - Forum: Installation & Setup - Replies (3)

I recently finished building my site using code igniter on WAMP local server and tested it on a shared hosting server (from Namecheap). Then I got VPS hosting plan (from iPage) and uploaded the files and did the necessary configs. However, I got this error when I tried accessing the site:

An uncaught Exception was encountered
Type: Error
Message: Call to undefined function ctype_digit()
Filename: /home/eastngco/public_html/system/core/Security.php
Line Number: 600

Problem is, the suspect file, Security.php, is a code igniter system file which I never messed with (everything I wrote was within the application folder).

I posted this problem on stackoverflow and was asked to contact my web host to have ctype enabled for me. I did and they enabled the function but the problem still persists. iPage tech team emailed me proof that ctype has been enabled, and asked me to contact Code Igniter. What baffles is that the same script works perfectly on local server and on a shared hosting server.

I tried changing the error line from ctype_digit to is_numeric (based on suggestions i saw on the web), the error changed to 'undefined function mysqli'. Again i changed the databasedriver in config/database.php to mysql, and the error shifted to something else, which made me realize something was really amiss.

Please i need help fixing this issue as it is apparent my web host can't help


  Store Notification Messages
Posted by: chrismartinez99 - Yesterday, 09:03 AM - Forum: Best Practices - Replies (1)

Hi,

Not sure if this is the best place to post this, but here goes.

I'd like to keep all of my applications notification messages in one spot for easier maintenance. Right now I've created a library Messages and store all of the messages as constants, so then I can refer to them as Message::ERROR_WITH_SUBMISSION in the code, for example.Is this an accepted way?

Or should I be adding these types of messages be added to the constants.php file?

How would you go about this?

Thank you in advance,
Chris


  narrowed down error to call_hook('post_system')
Posted by: richb201 - 11-15-2017, 09:11 AM - Forum: General Help - Replies (5)

I am not sure why this is happening. If I run my code with xdebug enabled, apache crashes at line 559 of codeigniter.php. Since this is the codeigniter code and not in phpStorm not Apache, I figured that this might be the best place to try to resolve my issue. 
$EXT->call_hook('post_system');
I don't know what this is for but next the code goes to 

public function call_hook($which = '')
{
  if ( ! $this->enabled OR ! isset($this->hooks[$which]))
  {
     return FALSE;
  }

Which returns FALSE. 

And then directly to _shutdown_handler() below. Since $last_error is null, the _error_handler() does not get called and the system crashes. Is this the way this is supposed to work?

   function _shutdown_handler()
  {
     $last_error = error_get_last();
     if (isset($last_error) &&
        ($last_error['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING)))
     {
        _error_handler($last_error['type'], $last_error['message'], $last_error['file'], $last_error['line']);
     }
  }
}


  Form field generator, bootstrap dependent
Posted by: identity_one - 11-15-2017, 04:40 AM - Forum: Addins - No Replies

i made this small library while working on a project.
It generates form field html.

https://github.com/JhulFramework/ci_bootstrap


  Using JSON in data attributes with JS
Posted by: skunkbad - 11-14-2017, 03:16 PM - Forum: Lounge - Replies (6)

I don't know if it's considered bad practice, or if it's the way everyone does it, but I find myself inserting JSON data into HTML element attributes all the time. So, for instance:

PHP Code:
foreach( $query->result_array() as $row )
    
$arr[] = (object) array_map'html_escape'$row );

$json json_encode$arr );

$json_string str_replace([
    
'&quot;',
    
'&apos;',
    
'& #039;' // space here for codeigniter forum
], [
    
'\u0022',
    
'\u0027',
    
'\u0027'
], $json ); 

Now I know that json_encode has options like JSON_HEX_APOS and JSON_HEX_QUOT, but I also want to use html_escape() which is why I'm using str_replace the way I am. This allows me to do this:


PHP Code:
echo '<div data-json=\'' $json_string '\'>'

Then later in my json I can use JSON.parse() on the contents of that data-json attribute.

What are your thoughts here? Is there a better way?


  Codeigniter 3.1.6 with PHP7.1 and Nginx
Posted by: sameernaqvi - 11-14-2017, 08:28 AM - Forum: Installation & Setup - Replies (1)

Thanks for the continuous updates. Last week I have installed php7.1 on my development machine in order to upgrade all the company's websites. Every think is seems fixed now except the following errors.

A PHP Error was encountered
Severity: 8192
Message: Function mcrypt_get_iv_size() is deprecated
Filename: libraries/Encrypt.php
Line Number: 315

A PHP Error was encountered

Severity: 8192

Message: Function mcrypt_decrypt() is deprecated

Filename: libraries/Encrypt.php
Line Number: 325

I am using codeigniter 3.1.6 though.
It seems like required to update the core Encrypt.php where the functions are mcrypt_get_iv_size() and mcrypt_decrypt() as they are deprecated.

Could you help me how to fix the core lib error or should I wait for next release as I use this Encrypt lib many places?
Your help in this regards will be helpful.



Attached Files Thumbnail(s)
   


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.