🎉 سال نو، مهارت نو، مشاوره رایگان نقشه راه برنامه نویسی (آفر ویژه ثبت نام قبل از افزایش قیمت 🔥)
۰ ثانیه
۰ دقیقه
۰ ساعت
۶ rahnama
ارور در گرفتن دیتا از دیتا بیس
rahnama حل شده توسط rahnama

سلام روز بخیر

وقتی میخوام از دیتابیس اون دیتایی که ثبت کردم بگیرم با این ارور مواجه میشم همه چی رو. با خود استاد چک کردم متوجه خطام نمیشم

با توجه به اینکه تمامی کد‌ها در پروژه ی قبلی تست شدن

ممنون میشم کمک کنید.

سلام محمد جان، لطفاً کدتون رو هم بفرستین تا بتونیم راهنمایی تون کنیم.

صادق برزگر ۲۶ شهریور ۱۴۰۲، ۱۴:۲۸
namespace App\\Controllers;
use App\\Models\\Contact;
class HomeController {
    private $contactModel ;
    public function __construct(){
        $this->contactModel = new Contact();
    }
    public function index()
    {
        echo "hi from controller of phonebook";
        $allContacts = $this->contactModel->getAll();
        nice_dump($allContacts);
    }
    
}
rahnama ۲۶ شهریور ۱۴۰۲، ۱۴:۳۳
namespace App\\Models\\Contracts;
use Exception;
use Medoo\\Medoo;
abstract class MysqlBaseModel extends BaseModel
{
  
    public  function __construct($id = null){
    //$this->connection = new \\PDO( "mysql:dbname={$_ENV['DB_NAME']};host=$_ENV{['DB_HOST']}",$_ENV['DB_USER'],$_ENV['DB_PASS']);
   try {
  $this->connection= new Medoo([
    
        'type' => 'mysql',
        'host' => $_ENV['DB_HOST'],
        'database' => $_ENV['DB_NAME'],
        'username' => $_ENV['DB_USER'],
        'password' => $_ENV['DB_PASS'],
     
        // [optional]
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_general_ci',
        'port' => 3306,
     
        // [optional] The table prefix. All table names will be prefixed as PREFIX_table.
        'prefix' => '',
     
        // [optional] To enable logging. It is disabled by default for better performance.
        'logging' => true,
     
        // [optional]
        // Error mode
        // Error handling strategies when the error has occurred.
        // PDO::ERRMODE_SILENT (default) | PDO::ERRMODE_WARNING | PDO::ERRMODE_EXCEPTION
        // Read more from https://www.php.net/manual/en/pdo.error-handling.php.
        'error' => \\PDO::ERRMODE_EXCEPTION,
     
        // [optional]
        // The driver_option for connection.
        // Read more from http://www.php.net/manual/en/pdo.setattribute.php.
     
        // [optional] Medoo will execute those commands after the database is connected.
        'command' => [
            'SET SQL_MODE=ANSI_QUOTES'
        ]
    ]);
   } catch (Exception $a) {
    echo "Connection Faild : " . $a->getMessage();
   }
   if (!is_null($id)) {
    nice_dump( $this->find($id)) ;
    }
    }
    # Creat (insert)
    public function create($new_data) : int
    {
        $this->connection->insert($this->table,$new_data);
        return(int)$this->connection->id();
    }
    # Read (select)
    public function find($id)
    {
         $record = (object)$this->connection->get($this->table,"*", [$this->primaryKey=>$id]);
        foreach($record as $col => $val)
            $this -> attributes[$col]=$val; 
          return $this;
    }
    public function getAll(){
        return $this->connection->select($this->table,['*']); ;
    }
    public function get(array $columns, array $where) : array{
        
       return $this->connection->select($this->table, $columns, $where); 
    }
    # Update
    public function update(array $data,array $id) : int
    {
     return (int)$this->connection-> update($this->table, $data,[$this->primaryKey=>$id]);
         
    }
    # Delete      
    public function delete(array $id) : int
    {
        return (int)$this->connection-> delete($this->table,[$this->primaryKey=>$id]);
        
    }
    public function remove():int{
        $record_id =$this->{$this->primaryKey} ; 
        return $this->delete([$this->primaryKey=>$record_id]);
    }
    public function save():int{
        $record_id =$this->{$this->primaryKey} ; 
        return $this->update($this->attributes,[$this->primaryKey=>$record_id]);
    }
}
    
rahnama ۲۶ شهریور ۱۴۰۲، ۱۴:۳۶
namespace App\\Core\\Routing;
use App\\Core\\Request;
use App\\Core\\Routing\\Route;
use Exception;
class Router {
    private $request;
    private $routes;
    private $current_route;
    const BaseController = '\\App\\Controllers\\\\';
    public function __construct()
    {
        $this->request = new Request;
        $this->routes = Route::routes();
        $this->current_route = $this->findRoute($this->request) ?? null;
        # run middleware here 
        $this->run_route_middleware();
    }
    private function run_route_middleware()
    {
         $middleware = $this->current_route['middleware'];
         foreach($middleware as $middleware_class)
        {
            $middleware_obj = new $middleware_class;
            $middleware_obj -> handle();
        }
                
    }
    public function findRoute(Request $request)
    {
 
            foreach ($this->routes as $route){
                if(!in_array($request->method(),$route['method']))
                {
                    return false;
                }
                if($this->regex_matched($route)){
                     return $route;
                }
            }
            return null;
     }
     public function regex_matched($route){
        global $request;
        $pattern = "/^". str_replace(['/','{','}'],['\\/','(?<','>[-%\\w]+)'],$route['uri'])."$/";
        $result = preg_match($pattern, $this->request->uri(), $matches);
        if(!$result){
            
            return false;
        }
        // nice_dump($matches);
       
         foreach ($matches as $key => $value) {
            if(!is_int($key)){
                 $request->add_route_param($key,$value);
             }
         }
        return true;
     }
     public function dispatch404(){
        header("HTTP/1.0 404 Not Found");
        view("errors.404");
        die();
     }
     public function run()
     {
        # 405 : invalid request method
        // if($this->invalidRequest($this->request)){
        //     $this->dispatch405;
        // }
        # 404 : uri not exists
        
        if(is_null($this->current_route))
        {  
         $this->dispatch404();
        }
        $this->dispatch($this->current_route); 
     }
     private function dispatch($route)
     {
        $action = $route['action'];
        # action : null
        if (is_null($action) || empty($action))
        {
          return;
        }
        # action : clousure
        if(is_callable($action)){
            $action();
            //call_user_func($action);
        }
        # action : Controller@method
        if(is_string($action))
        $action=explode('@',$action);
        # action : ['Controller','method']
        if(is_array($action))
        $class_name = self::BaseController. $action[0];
        $method=$action[1];
        if(!class_exists($class_name)){
            throw new Exception("Class $class_name not exist!!");
        }
        $controller = new $class_name();
        $controller->{$method}();
     }
}
rahnama ۲۶ شهریور ۱۴۰۲، ۱۴:۳۸

سلام روز بخیر 

من هنوز نتونستم این مشکل رو حل کنم و گیر کردم تو ادامه پروژه ممنون میشم کمک کنید.

 

 

 

 

در رابطه با فرم جدید سایت 

یکسری از سر فصل‌ها هست که من تکمیل کردم یا اینکه حداقل 70 تا 80 درصد تکمیل شدن ولی الان برای من زده دیده نشده 

و اینکه در فرم قبل میشد در کنار کادر ویدیو بین سر فصل‌ها جا به جا شد 

در این حالت جدید فقط بین جلاسات سرفصل انتخاب شده  این امکان وجود داره 

ضعف به حساب نمیاد اما حالت قبل خیلی کارامدتر بود

و اینکه قرار بود تمیرن هم اضاف بشه به سایت!!!!

 

در کل که اپدیت خیلی خوبی بود خسته نباشید به تیم سون لرن  

rahnama ۲۸ شهریور ۱۴۰۲، ۰۷:۱۵

مشکل حل شد.

بهترین پاسخ
rahnama ۲۸ شهریور ۱۴۰۲، ۰۷:۴۵