حل مشكلة المسارات علي نظام التشغيل وندو
السلام عليكم ورحمة الله وبركاته
هناك مشكلة في المسارات الخاصة بlaravel
حيث اننا نعلم ان انظمة تشغيل mac , linux تستخدم في الفصل بين المسارات
/ اما انظمة التشغيل windows فتستخدم \ وبالتالي في حال اردنا ان نقوم باستدعاء ملف معين
من مجلد app مثلا في نظام التشغيل وندوز سيكون كالتالي
C:\user\5dmat-web\app
اما في انظمة التشغيل linux , mac
سوف يصبح كالتالي
C:/user/5dmat-web/app
هذة هي المشكلة باختصار في لغة php هناك ثابت اسمه
DIRECTORY_SEPARATORففي حالة mac وlinux تصبح قيمة هذا الثابت / اما في الوندوز فيصبح \
في laravel في الدوال الخاصة بالمسارات مثلا
app_path(); storage_path(); database_path();لم يتم مراعة هذة النقطة وبالتالي يحدث اخطأ في حالة استدعاء الملفات
الحل كالتالي
افتح المسار التالي
bootstrap/autoload.phpاولا نعرف ثابت جديد نضع فيه الثابت الخاص بال DIRECTORY_SEPARATOR
define('DS', DIRECTORY_SEPARATOR);ثانيا ضع الدالة التالية
if (! function_exists('path')) { /** * Get the path to the application folder. * * @param string $path * @return string */ function path($path) { return str_replace(['/' , '\\'] , DS , $path); } }ثالثا الان يمكننا اعادة كتابة الدالة app_path()
في نفس الملف بحيث تعمل الدالة الخاصة بنا
بدلا من الدالة الخاصة بlaravel كالتالي
if (! function_exists('app_path')) { /** * Get the path to the application folder. * * @param string $path * @return string */ function app_path($path = '') { return app('path').($path ? DS.path($path) : path($path)); } }الان اصبح شكل الملف كالتالي
define('LARAVEL_START', microtime(true)); /* |-------------------------------------------------------------------------- | Register The Composer Auto Loader |-------------------------------------------------------------------------- | | Composer provides a convenient, automatically generated class loader | for our application. We just need to utilize it! We'll require it | into the script here so that we do not have to worry about the | loading of any our classes "manually". Feels great to relax. | */ define('DS', DIRECTORY_SEPARATOR); if (! function_exists('app_path')) { /** * Get the path to the application folder. * * @param string $path * @return string */ function app_path($path = '') { return app('path').($path ? DS.path($path) : path($path)); } } if (! function_exists('path')) { /** * Get the path to the application folder. * * @param string $path * @return string */ function path($path) { return str_replace(['/' , '\\'] , DS , $path); } } require __DIR__.'/../vendor/autoload.php';
فريق عمل خدمات ويب
لا يوجد تعليقات حتي الان