Jump to content

Destramic

Members
  • Posts

    968
  • Joined

  • Last visited

Everything posted by Destramic

  1. when trying to call get_class($this) it will return the namespace of my class Application\Models\User_Model But what im really after is just User_Model... is there a way of actually getting the class name and not the namespace itself? thought i'd ask before making a class for that...thank you
  2. hey im tring to match words which contain double s at the end...ie. address, business, class etc...so that is so i can put a ' at the end... class' if (preg_match("/ss$/", $name)) { $name = $name . "'"; } any help with the regular expression would be great thank you
  3. hey guys im in a bit trouble trying to use window offset() function. basically i have a fixed header and what im trying to accomplish is for when the user scroll past a certain point the header content will change...im not sure if im going about this the right way or even sure if it is possible with a fixed header. any help would be grateful thank you <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> <style type="text/css"> body{ margin:0px; background:#FFFFFF; } .header-cont { width:100%; position:fixed; top:0px; } .header { height:50px; background:#F0F0F0; border:1px solid #CCC; width:960px; margin:0px auto; } .content { width:960px; background: #F0F0F0; border: 1px solid #CCC; height: 2000px; margin: 70px auto; } </style> <script> $(window).scroll(function(){ var position = $('#position').offset().top; if ($(window).scrollTop() > position) { alert('hey'); // Change header content } }); </script> </head> <body> <div class="header-cont"> <div>FIXED HEADER</div> </div> <br /> <div id='position'></div> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> CONTENT HERE! </body> </html>
  4. hey guys im having a problem aligning a div so its vertically aligned middle...the objects im having the difficulty with is "search-bar" and "quick-links" which are apart of the "search_bar_container"...i;ve been fiddling about with it but have had no luck...css isn't really my thing so any pointer will be greatly appreciated thank you <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script> $(document).ready(function() { $("#list-icon").click(function() { if ($('#top-bar-media-menu').is(":visible")) { $('#top-bar-media-menu').hide("fast"); } else { $('#top-bar-media-menu').show("fast"); $('#top-bar-media-menu').focus(); } }); }); </script> <style> body { margin: 0px; } div#top-bar-media-menu { display: none; } div#header #left-link { display: inline-block; vertical-align: middle; padding: 5px; } div#header #right-link { float: right; line-height: 45px; padding-right: 10px; } div#header #list-icon { background-image: url('list.png'); vertical-align: middle; display: inline-block; height: 48px; width: 48px; } div#header #home-icon { background-image: url('home.png'); background-color: #505050; vertical-align: middle; display: inline-block; height: 48px; width: 48px; } div#header #arrow-down { background-image: url('arrow_down.png'); vertical-align: middle; display: inline-block; height: 16px; width: 16px; } div#header #top-bar-container { background-color: #000000; width: 100%; border-radius: 3px; position:relative } div#header #top-bar-desktop { background: -moz-linear-gradient(top, #505050, #343434); border: 1px solid #080808; width: 85%; height: 48px; margin-left: auto; margin-right: auto; border-top-right-radius: 3px; border-bottom-right-radius: 3px; font-family: Verdana,Arial,sans-serif; font-size: 12px; color: #FFFFFF; vertical-align: middle; } div#header #top-bar-media { display: none; } div#search_bar_container { width: 85%; height:80px; margin-left: auto; margin-right: auto; position:relative; } div#search_bar_container #logo { display: inline-block; background-image: url('logo.png'); height: 80px; width: 220px; } div#search_bar_container #search-bar { line-height: 45px; display: inline-block; position:absolute; width: 50%; height: 40px; } input#search { position: relative; width: 40%; border: 1px solid #080808; height: 30px; border-radius: 20px; font-family: Verdana,Arial,sans-serif; font-size: 14px; color: #000000; vertical-align: middle; } div#search_bar_container #quick-links { display: inline-block; vertical-align: middle; } @media all and (max-width:500px) { div#header #top-bar-desktop { display: none; } div#header #top-bar-media { display: block; background: -moz-linear-gradient(top, #505050, #343434); border: 1px solid #080808; width: 85%; height: 45px; margin-left: auto; margin-right: auto; border-top-right-radius: 3px; border-bottom-right-radius: 3px; font-family: Verdana,Arial,sans-serif; font-size: 11px; color: #FFFFFF; } } </style> </head> <body> <div id='header'> <div id='top-bar-container'> <div id='top-bar-media'> <div id="list-icon"></div> </div> <div id='top-bar-desktop'> <div id='home-icon'></div> <span id='left-link'>Register / Login</span> <span id='left-link'>News</span> <span id='left-link'>My Account</span> <div id='arrow-down'></div> <span id='right-link'>Language</span> </div> </div> <div id='search_bar_container'> <div id='logo'></div> <div id='search-bar'><input id='search' type='text'/></div> <div id='quick-links'>quick links here<div> </div> </div> <div id='top-bar-media-menu'>menu here</div> </body> </html>
  5. hey guys im wdondering if there's a magic method which works like __GET() but allows you to put a parameter in...thank you <?php class test { public function run() { $this->object->('string'); // __get with parameter? } public function __get($value) { return $this->{$value} } } ?>
  6. using the code above will remove all sessions and data set...im only want to unset a particualr session not all...i tried using session_unset which worked great...although the function unappreciated
  7. Well I use a name space which will make my sessions look like $_SESSION['authentication']['id']; Would I put that instead of session_name()? Thank you
  8. hey guys im having a spot of botter unsetting, destroying a session which has been given a cookie lifetime...i know it is possible to destroy all sessions using session_destroy() but i want to destory a particials session and not all of them. here is my method if anyone can give some advice on how i could do this please...thank you public function destroy($name = null) { $namespace = $this->_namespace; $sessions = $_SESSION[$namespace]; if ($name == null) { foreach ($sessions as $name => $value) { $session = $sessions[$name]; unset($sesion); if (isset($session)) { // sessions with lifetime ini_set('session.cookie_lifetime', 0); ini_set('session.gc_max_lifetime', 0); ini_set('session.gc_probability', 1); ini_set('session.gc_divisor', 1); $session; } } } else { unset($sessions[$name]); } session_regenerate_id(true); }
  9. altough i do have a problem calling static methods $auth = new \Authentication\Authentication::singleton(); with static i'll work fine...does namespacing also allow you to call self and parent? thank you
  10. how my customer model looks: namespace Libray\Models; use MVC\Model\Model as Model; class Index_Model extends Model { } autoloader: use Exception\Autoloader as Exception_Handler; class Autoloader { protected $_class_prefix = ''; protected $_class_paths = array(); protected $_ignore_directories = array('.', '..', '.settings'); public function __construct() { spl_autoload_register(array($this, 'load_class')); $this->get_class_paths(); } protected function is_collision($file) { $paths = $this->_class_paths; $file = $file . '.class.php'; $matches = 0; foreach ($paths as $class_path => $file_name) { if (substr($class_path, -strlen($file)) === $file) { $matches++; if ($matches > 1) { return true; break; } } } return false; } protected function load_class($file) { $file = strtolower($file); $paths = $this->_class_paths; try { if (preg_match('/\\\\/', $file)) { $file = str_replace('\\', DS, $file) . '.class.php'; foreach ($paths as $class_path => $file_name) { if (substr($class_path, -strlen($file)) == $file) { require_once $class_path; break; } } } else { $path = array_search($file, $paths); if (!$this->is_collision($file)) { if (!class_exists($file, false) && file_exists($path)) { require_once $path; } else { throw new Exception_Handler(sprintf("Class '%s' not found.<br />\n", $file)); } } else { throw new Exception_Handler(sprintf("Unable to load '%s' due to name collision.<br />\n", $file)); } } } catch (Exception_Handler $e) { echo $e->getMessage(); } } protected function get_class_paths($path = PARENT_DIRECTORY_PATH) { $ignore_directories = $this->_ignore_directories; $dh = opendir($path); if ($dh) { while (false !== ($file = readdir($dh))) { if (!in_array($file, $ignore_directories)) { if (is_dir($path . DS . $file)) { $this->get_class_paths($path . DS . $file); } else if (preg_match('/\.class\.php$/i', $file)) { $entry = $path . DS . $file; $file = substr($file, 0, -10); $this->_class_paths[$entry] = $file; } } } closedir($dh); } } } autoloader works sweet altough i still have a few alterrations to make like cache and prefix...hope im on the right track...thanks guys
  11. thanks you guys...just a few more things I wanna ask if you don't mind me picking you brains if I namespace a class and call a call inside that class' method like so $class = new hello; it comes back with a error: cannot find class my\namespace\hello; is that because its only looking in the my\namespace directory and I would need to call the hello class (eg. utilities\hello) by its actually namespace?...but what happens if the class hello doesn't have a namespace?...is it impossible to load it?
  12. But what I'm confused at is...I've started to adapt my framework classes to being namespaced but I'd also have to add namespaces to my customer controllers:/...should my controllers and models be called without being namespaced?...so should all classes be namespaced in reality...thank you
  13. hey guy I've just recently re-altered my autoloader class which works with namespaces but it also calls classes which aren't namespaced, like so: $class = new myclass(); instead of $class = new Class\Myclass; im wondering have i defeated the whole point of namespacing and if all my classes should actually be namespaced hope its not such a pointless question
  14. wow well that's some great information...SSL is new to with a lot of other things :/...but im looking forward to playing around with it when I buy my server in the next couple of months... thank you...you help is much appreciated *bookmarked
  15. @jacques1, thank you for your information...that has helped me greatly ...one more thing I want to implement SSL to my site...would I have to put SSL into my auth class or would that be a completely different security that would works along side my auth class? if you know of a good tutorial about this so I can understand more please?...the articles ive read just don't seem to sink in thank you again for your help
  16. well this is why im asking the question...but anyways that was the way I used to do it by using the session id but back on the point about storing the username as a session or possibly as a cookie if the user wishes to be remembered...do I then just select the user in the database via just the username which will then get me his/her credentials like email and access level? I read up about whirlpool hashing which suppose to be the best to encrypt passwords...what do you think? function getPasswordSalt() { return substr( str_pad( dechex( mt_rand() ), 8, '0', STR_PAD_LEFT ), -8 ); } // calculate the hash from a salt and a password function getPasswordHash( $salt, $password ) { echo $salt . ( hash( 'whirlpool', $salt . $password ) ); } // compare a password to a hash function comparePassword( $password, $hash ) { $salt = substr( $hash, 0, 8 ); return $hash == getPasswordHash( $salt, $password ); } // get a new hash for a password $hash = getPasswordHash( getPasswordSalt(), "hello" );
  17. hey guys im after a bit of information regarding user authentication please... now I have previously save a users session id in my database after they have logged in so when leaving and coming back to the site im able to compare session id's to get username etc...is this still the way or am I now a little old fashioned? a few more things...do I save information such as username, access level as a session or cookie?...and what is the best way to encrypt passwords please? thank you
  18. thanks @barand oh ok so if I do LEFT JOIN categories c ON c.category_id = sc.category_id WHERE c.name = 'test' and something similar for users? regarding concat() it was the only way I could get the query working as the field list_duration is a enum just using the value of the field wasn't working
  19. SELECT i.item_id, i.title, i.price, i.p_and_p, SUM(i.price + i.p_and_p) AS `total_price`, i.listing, i.condition, i.start_date_time, i.listing_duration, CONVERT_TZ(DATE_ADD(i.start_date_time, INTERVAL concat(i.listing_duration) DAY), '+00:00', u.time_zone) AS `end_date_time` FROM items i LEFT JOIN sub_categories sc ON sc.sub_category_id = i.sub_category_id LEFT JOIN categories c ON c.name = 'test' JOIN users u WHERE u.username = 'Destramic' AND i.start_date_time < NOW() AND DATE_ADD(i.start_date_time, INTERVAL concat(i.listing_duration) DAY) >= NOW() I'm having a problem with my query returning more than 1 rows...I've even copied the row which is returning to see if that'll return 2 rows but it doesn't can anyone explain why this is happening please?
  20. im trying to get this ajax function working but for some reason it runs the error function...I've corresponded with the manual and I can't see a fault...any advise would be great...thanks $(document).ready(function() { $.ajax( { url: "items.php", dataType: "json", data: '<?php echo $data; ?>', timeout: '2000', cache: false, error: function(data) { alert('error'); }, success: function(data) { $.each(data, function() { $("#table").append('<div class="row"><span class="cell">'+ data.title +'</span><span class="cell"></span><span class="cell"></span></div>'); }); } }); });
  21. SELECT i.item_id, i.title, i.price, @end_date_time := DATE_ADD(i.start_date_time, INTERVAL 10 DAY), CONVERT_TZ(@end_date_time, '+00:00', u.time_zone) AS `end_date_time` FROM items i LEFT JOIN sub_categories sc ON sc.sub_category_id = i.sub_category_id LEFT JOIN categories c ON c.name = 'Video Games & Consoles' JOIN users u WHERE u.username = 'Destramic' AND i.start_date_time < NOW() AND DATE_ADD(i.start_date_time, INTERVAL 10 DAY) >= NOW() works like a charm...thank you
  22. ok I've taken out the unix_timestamp()...but the query isn't producing a result @end_date_time = 2014-08-05 22:51:45 @start_date_time = 2014-07-26 22:51:45 now obviously these vars match my WHERE's clause...which should bring a result back.... @end_date time >= now() @start_date_time < now() confused....
  23. im having problem comparing timestamps in my where clause for some strange reason...my query works perfect but when adding WHERE it doesn't bring up a result although it should...I've been playing about with it for almost a day now...and it doesn't make sense unix_timestamp values start_date_time 1406411505 end_date_time 1407275505 now 1406461573 my query SELECT i.item_id, i.title, i.price, @start_date_time := CONVERT_TZ(i.start_date_time, '+00:00', u.time_zone), @end_date_time := DATE_ADD(@start_date_time, INTERVAL 10 DAY), @end_date_time AS `end_date_time` FROM items i LEFT JOIN sub_categories sc ON sc.sub_category_id = i.sub_category_id LEFT JOIN categories c ON c.category_id = sc.category_id JOIN users u ON username = 'Destramic' WHERE UNIX_TIMESTAMP(@start_date_time) < UNIX_TIMESTAMP(NOW()) AND UNIX_TIMESTAMP(@end_date_time) >= UNIX_TIMESTAMP(NOW()) if anyone can diagnose my problem I'd it would be much appreciated
  24. I've been reading a few tutorials on how the best way to search key words in a database and at the moment im trying to get this query to work but its coming back with a error: #1191 - Can't find FULLTEXT index matching the column list query: SELECT title, description FROM items WHERE MATCH(title, description) AGAINST('xbox') any help or advise on how the best way to search 2 columns on matching words...thank you
  25. <?php class Action { protected $_request; protected $_response; protected $_model; protected $_view; public function __construct(Request $request, Response $response) { $this->set_request($request)->set_response($response)->set_view($request, $response)->set_model(); // if request requires partial then do this $partial = Partial::singleton(); $view = $this->get_view(); $view->set_partial($partial); $partial->set_view(clone $view); } protected function set_request(Request $request) { $this->_request = $request; return $this; } protected function set_response(Response $response) { $this->_response = $response; return $this; } protected function set_view(Request $request, Response $response) { $this->_view = new View($request, $response); return $this; } public function get_request() { return $this->_request; } public function get_response() { return $this->_response; } public function get_view() { return $this->_view; } public function dispatch($method, $parameters) { if ($this->get_request()->is_dispatched()) { if(method_exists($this, $method)) { call_user_func_array(array($this, $method), $parameters); } else { echo "unable to load method"; } } } public function __get($property) { $property = '_' . $property; if (property_exists($this, $property) && $property !== '$this->_request' && $property !== '$this->_responce') { return $this->$property; } return false; } public function set_model() { $class_name = get_class($this); $model_name = trim($class_name, "_Controller"); $model_name = strtolower($model_name); $property_name = '_' . $model_name; $model_name = Inflection::singularize($model_name); $model_name = ucfirst($model_name); $model_class = $model_name . '_Model'; $this->{$property_name} = new $model_class(); } } <?php class View { protected $_variables = array(); protected $_helpers = array(); public function __construct(Request $request, Response $response) { } public function __set($name, $value) { $this->_variables[$name] = $value; } public function __get($name) { return $this->_variables[$name]; } public function __call($name, $parameters) { $helper = $this->get_helper($name); if (!$helper) { $helper = call_user_func_array(array(new $name(), '__construct'), $parameters); $this->set_helper($name, $helper); } return $helper; } protected function set_helper($helper, $instance) { $this->_helpers[$helper] = $instance; } protected function get_helper($helper) { if (isset($this->_helpers[$helper])) { return $this->_helpers[$helper]; } return false; } public function set_partial(Partial $partial) { if ($partial instanceof Partial) { $this->set_helper('partial', $partial); } } public function render($file) { if (preg_match("/\.html$/i", $file)) { require_once PRIVATE_DIRECTORY . 'application' . DS . 'views' . DS . $file; } } } <?php class Partial { protected $_view; protected $_templates; protected static $_instance = null; public static function singleton() { if (self::$_instance == null) { self::$_instance = new self(); } return self::$_instance; } public function set_view(View $view) { $this->_view = $view; } public function __set($name, $options = array()) { $this->_templates[$name]; $this->_templates[$name]['path'] = $options[0]; $this->_templates[$name]['variables'] = $options[1]; } public function __get($name) { // when $this->paertial()->header; is called in view template // it extracts variables and includes template view render() method $file = $this->_templates[$name]['path']; $variables = $this->_templates[$name]['variables']; } } Hey guys im trying to make alternations to my personal framework by adding a Partial class as a helper to the View class so that I'm able to add partial templates in my bootstrap and load accordingly in my view template like a header and footer. what im after is a bit of advise on the functioning of my Action/View and Partial please (not sure if what im doing is really right although it does work) Basically my Controller will extend my action where a model and view is made for my controller to use. Then my partial class is sent as a helper to my view and a clone of view sent to my partial so that im able to use the view class in my partial to render my header and variables. (is this the correct way? or a good method?) here's my code...like I said any advise would be greatly appreciated... thank you
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.