joostvanveen / build-a-cms-with-codeigniter

Source code for the Tutsplus course 'Build a CMS with Codeigniter'
53 stars 55 forks source link

Some Changes in usere #6

Closed rsa408 closed 10 years ago

rsa408 commented 10 years ago

Dear friend.

This is me, I want to do some changes in databases and adding 3 level of users administrators, bloggers and joined readers. i am started it newly and i will have many problems firs of all is that in user controller of admin dashboard when I run this query :

$this->db->select('users.user_id,user_info.name,user_info.fam'); $this->db->from('users'); $this->db->join('user_info', 'users.user_id = user_info.user_id'); $data= $this->db->get(); var_dump($data);

the result is :

object(CI_DB_mysql_result)#15 (8) { ["conn_id"]=> resource(34) of type (mysql link) ["result_id"]=> resource(35) of type (mysql result) ["result_array"]=> array(0) { } ["result_object"]=> array(0) { } ["custom_result_object"]=> array(0) { } ["current_row"]=> int(0) ["num_rows"]=> int(2) ["row_data"]=> NULL }

I will be appropriated if you help me to finish these changes.

kindly regards

That 3 Tables are:

CREATE TABLE IF NOT EXISTS user_type ( user_type int(4) NOT NULL AUTO_INCREMENT, type_name varchar(15) COLLATE utf8_bin DEFAULT NULL, PRIMARY KEY (user_type), UNIQUE KEY user_type (user_type) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=4 ;

INSERT INTO user_type (user_type, type_name) VALUES (1, 'Administrator'), (2, 'Blogger'), (3, 'User');

CREATE TABLE IF NOT EXISTS users ( user_id int(9) NOT NULL AUTO_INCREMENT, email_add varchar(35) COLLATE utf8_bin DEFAULT NULL, password varchar(128) COLLATE utf8_bin NOT NULL, last_login datetime NOT NULL, usr_typ_id int(4) DEFAULT NULL, permissions varchar(50) COLLATE utf8_bin DEFAULT NULL, PRIMARY KEY (user_id), UNIQUE KEY email_add (email_add), KEY fk_usr_typ_id (usr_typ_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=92090005 ;

INSERT INTO users (user_id, email_add, password, last_login, usr_typ_id, permissions) VALUES (92090001, 'reza.salimpour@gmail.com', '8389', '2014-01-03 22:45:02', 1, ''), (92090002, 'parsian.aria@gmail.com', '9291', '2014-01-03 22:47:27', 2, ''), (92090003, 'rs_408@yahoo.com', '105229', '2014-01-03 22:47:27', 3, ''), (92090004, 'asr7@ymail.com', '1052', '2014-01-03 22:47:27', 1, '');

ALTER TABLE users ADD CONSTRAINT fk_usr_typ_id FOREIGN KEY (usr_typ_id) REFERENCES user_type (user_type);

CREATE TABLE IF NOT EXISTS user_info ( id int(9) NOT NULL AUTO_INCREMENT, user_id int(9) DEFAULT NULL, name varchar(25) COLLATE utf8_bin NOT NULL, fam varchar(45) COLLATE utf8_bin NOT NULL, cell varchar(12) COLLATE utf8_bin NOT NULL, company varchar(45) COLLATE utf8_bin DEFAULT NULL, PRIMARY KEY (id), UNIQUE KEY user_id (user_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=100000003 ;

INSERT INTO user_info (id, user_id, name, fam, cell, company) VALUES (100000001, 92090001, 'hamed', 'salim', '09149306211', ''), (100000002, 92090002, 'reza', 'salim', '09143711256', '');

ALTER TABLE user_info ADD CONSTRAINT user_info_ibfk_1 FOREIGN KEY (user_id) REFERENCES users (User_id);

joostvanveen commented 10 years ago

Just use

$data= $this->db->get()->result_array();

And your query will return an array instead of a Codeigniter query object.

rsa408 commented 10 years ago

Dear friend; I am very thank full for your pay attention, actually i want to ask this question via email but I thought maybe some people that follow your tutorial and decided to do some changes like me may need these guide in addition.

is it possible to be open this discussion for additional questions?

joostvanveen commented 10 years ago

Hi rsa408,

Ok. But I'm not sure whether I'll have time to respond myself, though...

Cheers, Joost

rsa408 commented 10 years ago

Hi Joost, Its me again. after studying more in my project, i have trouble in managing permission of users. first i decided to make each type users view system but when it took time also it was not manageable for exception cases. I found some permission class and libraries but i think i had to make a platform for user management groups and in users may have a customizability for different users . i remember i saw that I drupal. not exactly same thing something looks like that.

i will be happy to know, what would be your suggestion?

regards

joostvanveen commented 10 years ago

hi rsa408,

Ik I were you I'd use either Ion Auth or Sentry. Both are solid libraries with groups and roles built in. Ion Auth is Co only. Sentry is framework agnostic.

Cheers, Joost

Sent from my iPhone

Op 6 feb. 2014 om 21:27 heeft rsa408 notifications@github.com het volgende geschreven:

Hi Joost, Its me again. after studying more in my project, i have trouble in managing permission of users. first i decided to make each type users view system but when it took time also it was not manageable for exception cases. I found some permission class and libraries but i think i had to make a platform for user management groups and in users may have a customizability for different users . i remember i saw that I drupal. not exactly same thing something looks like that.

i will be happy to know, what would be your suggestion?

regards

— Reply to this email directly or view it on GitHub.

rsa408 commented 10 years ago

Dear Friend;

Hi

I have an other question i will be happy if you could help me.

I want to show a a tree-view or folder-view in my site which is based on Codeigniter mvc. Actually site will show a main category and en each category sub-categories and so on.

Subject tree -- Sub A
 - Sub A-1
   |
   -Sub A-1-1
   :

+- Sub B :

each nod may contain many articles which are related with many data on database.

how can i implement it?

joostvanveen commented 10 years ago

Hi,

If you have hierarchical data like this, that is more than two layers deep, you are best off using nested sets, also known as MPTT. I recommend you search for a third party solution here, because building a nested sets model yourself can get pretty complicated.

Cheers, Joost

√ Think Green - Keep it on the screen

Op 28 feb. 2014, om 17:54 heeft rsa408 notifications@github.com het volgende geschreven:

Dear Friend;

Hi

I have an other question i will be happy if you could help me.

I want to show a a tree-view or folder-view in my site which is based on Codeigniter mvc. Actually site will show a main category and en each category sub-categories and so on.

Subject tree -- Sub A
  • Sub A-1 -Sub A-1-1

    +- Sub B :

each nod may contain many articles which are related with many data on database.

how can i implement it?

— Reply to this email directly or view it on GitHub.