Jump to content

Destramic

Members
  • Content count

    922
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Destramic

  • Rank
    Prolific Member
  • Birthday 10/06/1986

Profile Information

  • Gender
    Male
  • Location
    United Kingdom

Contact Methods

  • Skype
    destramic
  1. Destramic

    Header problems

    Hey guys I include my header to my pages by adding this to the top of the page $this->render ('myheader.html'); The problem is I want to pass results from my db to the navigation menu, which would require me to assign vars in each controller view that includes the header. What is the best way to do this please? Another way I can think off is assigning the results to my view in my bootstrap ready for the controllers...but I'm sure there is a more logical way. Thank you
  2. Destramic

    date to mon - fri

    thats brilliant...thank you for your help Barand 👍 much appreciated.
  3. Destramic

    date to mon - fri

    thank you for your quick reply. i would also need friday's date. ive been testing via sql, and think ive almost made a breakthrough, but i get an error. SELECT DATE_ADD(DATE('2018-08-14'), INTERVAL - WEEKDAY(DATE('2018-08-14')) DAY) AS 'week_start', DATE_ADD(week_start, INTERVAL 5 DAY) AS 'week_end'
  4. Destramic

    date to mon - fri

    hey guys i have a little problem and not sure of the best way to tackle it, if you could help please. i have 2 url which could be like so tasks/ricky-powell/week/14/08/2018 tasls/ricky-powell/day/14/08/2018 now if /day/14/08/2018 then thats a simple query. SELECT task FROM tasks WHERE scheduled_date = '2018-08-14' but...if users selects to view tasks by week (mon-fri) then it becomes a little bit complicated. 14/08/2018 is today which is a tuesday, and i would need to get the range from date mon - fri. would it be easier to: 1. ensure weekly url is a monday? 2.work out the date (mon - fri) view mysql/php 3. something else. thank you.
  5. Destramic

    simple entity validator - critique

    I feel with annotation also your force to learn a new syntax...I could also use traits for certian fields that are use widley throughout my site, which is cool. I concur with what your saying, and I'd also be able to get rid of the abstract too. I'll implement what you've said and try to build upon that. Thank you for your great input once again.
  6. last year a made a validion script that works simular to this but using annotation (like symphony). it was very long winded and messy, but although it worked perfectly i was never happy with how complicated it was. well i had a brain wave last night on how to simplify a validator without any annotation bs! this took me minutes to write, and would be nice to have an overall critique from you guru's. validator: <?php class Validator { private $entities = array(); private $error_messages = array(); public function __construct(array $entities) { foreach($entities as $entity) { $this->check_entity($entity); } $this->entities = $entities; } private function check_entity($entity) { if (!is_object($entity)) { throw new Exception('Validator: Entity must be an object.'); } else if (!is_subclass_of($entity, 'Entity')) { throw new Exception('Validator: Parent entity has not been implimented.'); } return true; } public function validate(array $data) { foreach ($this->entities as $entity) { foreach ($data as $property => $value) { if (property_exists($entity, $property)) { $entity->{$property} = $value; } if (method_exists($entity, $property)) { call_user_func_array(array($entity, $property), array('value' => $value)); } } $this->error_messages = array_merge($this->error_messages, $entity->get_error_messages()); } } public function get_error_messages() { return $this->error_messages; } public function is_valid() { return empty($this->error_messages); } } login entity <?php include_once 'entity.class.php'; class Login extends Entity { public $username; public $password; public function username() { if (empty($this->username)) { $this->add_error_message('Username: username is empty'); } } public function password() { if (empty($this->password)) { $this->add_error_message('Password: password is empty'); } } } abstract entity <?php abstract class Entity { private $error_messages = array(); public function add_error_message(string $message) { $this->error_messages[] = $message; } public function get_error_messages() { return $this->error_messages; } } test it all out! <?php include_once 'validator.class.php'; include_once 'entity/login.class.php'; $validator = new Validator(array(new Login)); $post = array( 'username' => 'john.doe', 'password' => null ); $validator->validate($post); if (!$validator->is_valid()) { print_r($validator->get_error_messages()); } result: Array ( [0] => Password: password is empty ) the script will work with multiple entities too. thank you guys!
  7. Destramic

    custom framework - http response code pattern

    requinix thank you for your time in breaking down how things should work, as it's all alot clearer to me now and i'll be sure to adopt these changes into my framework. thanks again.
  8. Destramic

    custom framework - http response code pattern

    brilliant i understand how it should work now....i'll change my code around so the request and response get sent from front controller to my controller. that way i'll be able to run this code in my front controller if dispatched. $controller = $this->dispatcher->dispatch(); $response = $controller->get_repsonse(); if ($reponse->get_response_code !== 200) { // deal with respsone code! { else { $response->send(): } also should i send my view through my front controller to controller like request and response?...or initialize my view in my asbtract controller? thank you for your help!
  9. hey guys im trying to build custom http error pages into my framework but after days of thinking, i must admit defeat and ask for some help. ok so if i try to access a route which doesnt exist my dispatcher will send a 404 error in the send_404_error() method were http_reponse_code(404) is set and then it'll dispatch to the error controller (no problem). dispatcher: <?php namespace MVC\Dispatcher; use HTTP\Request; use HTTP\Response; use Exception; class Dispatcher { private $request; private $config; private $class; private $controller; private $method; private $dispatchable = null; public function __construct(Request $request, $config) { $this->request = $request; $this->config = $config; } public function dispatch(array $parameters) { if ($this->dispatchable) { $this->request->set_controller($this->controller); $this->request->set_parameters($parameters); $controller = new $this->class($this->request); $this->reset(); return call_user_func_array(array($controller, $this->method), $parameters); } else if ($this->dispatchable == false) { return $this->send_404_error(); } return false; } public function is_dispatchable(string $controller) { $this->format_controller($controller); if (!class_exists($this->class) || !method_exists($this->class, $this->method)) { return false; } return $this->dispatchable = true; } private function format_controller(string $controller) { if (substr_count($controller, ':') != 2) { throw new Exception('Dispatcher: Invalid controller format.'); } $this->controller = $controller; list ($module, $controller, $method) = explode(':', $controller); $this->class = $module . '\Controller\\' . $controller; $this->method = $method; } public function send_404_error() { if (isset($this->config->framework['http_error_controller'])) { $error_controller = $this->config->framework['http_error_controller']; if ($this->is_dispatchable($error_controller)) { (new Response)->set_response_code('404'); return $this->dispatch(array( 'status_code' => 404 )); } else { throw new Exception('Dispatcher: HTTP Error undispatchable.'); } } return false; } public function reset() { $this->class = null; $this->controller = null; $this->methid = null; $this->dispatchable = false; } } question what happens if i want to send a http 404 error in any of my controllers? <?php namespace Custom\Controller; class Test extends Controller { public function test($status_code) { // user not authed! (new Response)->set_response_code(404)->send(); } } when the 404 response is sent, i could check in send() method that the http_repsone_code() is 200, if not then dispatch to the error controller. if ($this->get_response_code() !== 200) { return (new Front_Controller($config))->run('custom:error:http_error', 404); } return $this->content all that being said there is still a http_repsone_code(404) after that snippit is run and the response will keep looping because the repsone code isn't 200. response: <?php namespace HTTP; use HTTP\Response\Header; class Response { private $content; public function __construct($content = null) { $this->set_content($content); } public function set_content(string $content = null) { $this->content = $content; } public function set_response_code(int $status_code) { http_response_code($status_code); } public function get_response_code() { return http_response_code(); } public function headers() { return new Header; } public function send() { echo $this->content; } } can someone please talk some sence into my on how i should handle http reponse codes in my framework. thank you.
  10. Destramic

    absolute position

    it was just me trying all options to add transparency to that div. but thank you both for you time and efforts help me
  11. Destramic

    absolute position

    thank you gizmola, clear worked like a dream. I'll also take a closer look at that article too the layout is looking great thanks to you guys, but im still having the problem with z-index not working when applied to menu div. the .body-container has opacity: 0.7; but i want .left-container (menu) layer to come forward so the background doesn't appear through it like so here is the updated html: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Dashboard</title> <link href="https://fonts.googleapis.com/css?family=Titillium+Web" rel="stylesheet"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> <style> *{ font-family: 'Titillium Web'; } body { background:url("https://image.ibb.co/h93Ndo/abstract.jpg") top right no-repeat; background-attachment:fixed; margin: 0; margin-top: 10px; } .body-container{ position: relative; display: flex!important; flex-direction: column; justify-content: stretch; align-items: stretch; min-height: 99vh; margin: auto; width: 97%; opacity: 0.7; z-index: -1; } .header{ flex-grow: 0; background: #3A98FD; border-top-left-radius: 15px; border-top-right-radius: 15px; z-index: 1; height: 70px; } .two-cols{ flex-grow: 1; display: flex; flex-direction: row; justify-content: stretch; } .left-container{ position: relative; display: flex; flex-direction: column; justify-content: flex-start; flex-grow: 1; flex-basis: 13%; z-index: 1; background: #3B4A53; } .content{ display: flex; flex-direction: column; justify-content: space-between; flex-grow: 1; flex-basis: 85%; background: #ffffff; z-index: 1; vertical-align: text-top; vertical-align: top; } .clear{ clear: both; } </style> </head> <body> <div class="body-container"> <div class="header"></div> <div class="two-cols"> <div class="left-container">menu</div> <div class="content"> Content </div> </div> <div class="clear"></div> </div> </body> </html> thank you for your help again guys!
  12. Destramic

    absolute position

    that works much better thank you max. when i try apply a margin to the top of the page it pushes the body down too...how can this be fixed please? and also i tried to add z-index to the header and left container to stop bg image showing through but its also not work. (trying to get the bg image to only show through content div) thanks again. updated: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Dashboard</title> <link href="https://fonts.googleapis.com/css?family=Titillium+Web" rel="stylesheet"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> <style> *{ font-family: 'Titillium Web'; } body { background:url("https://image.ibb.co/h93Ndo/abstract.jpg") top right no-repeat; background-attachment:fixed; margin-top: 10; } .body-container{ display: flex!important; flex-direction: column; justify-content: stretch; align-items: stretch; min-height: 100vh; margin: auto; width: 97%; opacity: 0.7; z-index: -1; } .header{ flex-grow: 0; background: #3A98FD; border-top-left-radius: 15px; border-top-right-radius: 15px; z-index: 1; } .two-cols{ flex-grow: 1; display: flex; flex-direction: row; justify-content: stretch; } .left-container{ display: flex; flex-direction: column; justify-content: flex-start; flex-grow: 1; flex-basis: 15%; z-index: 1; background: #3B4A53; } .content{ display: flex; flex-direction: column; justify-content: flex-end; flex-grow: 1; flex-basis: 85%; background: #ffffff; z-index: 1; } </style> </head> <body> <div class="body-container"> <div class="header">Here's the header</div> <div class="two-cols"> <div class="left-container">menu</div> <div class="content"> hello world </div> </div> </div> </body> </html>
  13. Destramic

    absolute position

    I'm having trouble getting the .body-container and .left-container to follow suit with the .content, the height of both divs don't seem to alter down. Also z-index doesnt work on .left-container as im trying to stop the background to show through that particular div. ive read it may be because of the absolue positioning. Any help on these matters would be great. thank you <!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <style> body { background:url("https://image.ibb.co/h93Ndo/abstract.jpg") top right no-repeat; background-attachment:fixed; margin: 0; } .body-container{ background-color: #ffffff; border-top-left-radius: 15px; border-top-right-radius: 15px; margin: auto; width: 98%; height: auto; position: absolute; top: 0; left: 0; bottom: 0; right: 0; opacity: 0.7; margin-top: 10px; } .header{ position:relative; display: block; width: 100%; background-color: #3A98FD; height: 70px; border-top-right-radius: 15px; border-top-left-radius: 15px; } .left-container{ display: block; color: #ffffff; float: left; background-color: #3B4A53; width: 12%; height: auto%; min-height: 100%; } .content{ position: absolute; display: inline-block; float: right; width: 100%; height: auto; min-height: 100%; } </style> </head> <body> <div class="body-container"> <div class="header"></div> <div class="left-container">menu</div> <div class="content"> <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>hello world </div> </div> </body> </html>
  14. you need a trigger $(document).ready(function() { $('.trigger').click(function(){ $('input.player_search').typeahead({ name: 'player_name', remote: 'mysql.php?query=%QUERY', }); }); }) // the html trigger <button class="trigger">Search</button> i see some big security risks with your php also...your database is open to sql injection, you need to get that sorted before putting your script live. http://php.net/manual/en/mysqli.real-escape-string.php if you used PDO instead of mysqli you probably wouldnt have this problem.
  15. Destramic

    Invalid numeric literal

    Thank you for your help...changing the int to string work perfectly
×

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.